The Fourth Dimension Space

枯叶北风寒,忽然年以残,念往昔,语默心酸。二十光阴无一物,韶光贱,寐难安; 不畏形影单,道途阻且慢,哪曲折,如渡飞湍。斩浪劈波酬壮志,同把酒,共言欢! -如梦令

POJ 2083-Fractal

此题与上一题类似,一次AC;
由于控制台屏幕太小 这次我将结果保存在文件中;
#include<iostream>
#include
<cmath>
#include
<algorithm>
#include
<cstdlib>
#include
<cstdio>
#include
<fstream>
using namespace std;

char mymap[2500][2500];

int leftdot;
int rightdot;
int topdot;
int bottomdot;


void figure(int x,int y,int degree)
{
    leftdot
=min(leftdot,y);
    rightdot
=max(rightdot,y);
    topdot
=min(topdot,x);
    bottomdot
=max(bottomdot,x);


    
if(degree==1)
    
{
        mymap[x][y]
='X';
    }

    
else
    
{

        
int dis=(int)pow((double)3,degree-2)*2;
        figure(x,y,degree
-1);
        figure(x,y
+dis,degree-1);
        figure(x
+dis,y,degree-1);
        figure(x
+dis/2,y+dis/2,degree-1);
        figure(x
+dis,y+dis,degree-1);
    }




}



int main()
{

    
int n;
    
int i,j;
    ofstream file;
    file.open(
"test.txt");
    
while(scanf("%d",&n))
    
{
        rightdot
=-100000000;
        leftdot
=100000000;
        topdot
=1000000000;
        bottomdot
=-1000000000;
        memset(mymap,
' ',sizeof(mymap));
        
if(n==-1)
            
break;
        figure(
1,1,n);
        
for(i=leftdot;i<=rightdot;i++)
        
{

            
for(j=topdot;j<=bottomdot;j++)
                file
<<mymap[i][j];
            file
<<endl;
        }

        file
<<'-'<<endl;
    }

    file.close();
    
return 0;
}


答案请见:/Files/abilitytao/test.txt

posted on 2009-03-27 23:44 abilitytao 阅读(558) 评论(0)  编辑 收藏 引用


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理