# The Fourth Dimension Space

## POJ 2083-Fractal

#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;
}

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