# The Fourth Dimension Space

## POJ 1941-The Sierpinski Fractal 感悟递归之美^_^

#include<iostream>
#include
<cmath>
#include
<cstdlib>
using namespace std;
#define MAX 100000000
#define MIN -100000000

char mymap[5000][5000];

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

void figure(int x,int y,int deep)
{

if(deep==1)

{

mymap[x][y]
='/';
mymap[x][y
+1]='_';
mymap[x][y
+2]='_';
mymap[x][y
+3]='\\';
mymap[x
-1][y+1]='/';
mymap[x
-1][y+2]='\\';
}

else

{

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

}

int main ()
{

int n;

int i,j;
leftdot
=MAX;
rightdot
=MIN;
topdot
=MAX;
bottomdot
=MIN;
memset(mymap,
' ',sizeof(mymap));
figure(
2500,2500,10);

while(scanf("%d",&n))

{

if(n==0)

break;

topdot
=2500-(int)pow((double)2,10)+1;
bottomdot
=topdot+(int)pow((double)2,n)-1;
leftdot
=2500+(int)pow((double)2,10)-(int)pow((double)2,n);
rightdot
=leftdot+(int)pow((double)2,n+1)-1;

for(i=topdot;i<=bottomdot;i++)

{

for(j=leftdot;j<=rightdot;j++)

{

printf(
"%c",mymap[i][j]);
}

printf(
"\n");
}

printf(
"\n");

}

return 0;
system(
"pause");
}

posted on 2009-03-27 22:08 abilitytao 阅读(2541) 评论(0)  编辑 收藏 引用