POJ 2083-Fractal

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

你可能感兴趣的:(POJ 2083-Fractal)