Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
递归做的,780k,94MS#include <iostream> #include <cmath> using namespace std; int n; char map[750][750]; void digui(int n,int x,int y) { if(n==1) map[x][y] = 'X'; else { int size = pow(3+0.0,n-2); digui(n-1,x,y); digui(n-1,x+2*size,y); digui(n-1,x+size,y+size); digui(n-1,x,y+2*size); digui(n-1,x+2*size,y+2*size); } } int main() { int i,j; while(cin>>n && n!=-1) { int size = pow(3+0.0,n-1); for(i=1;i<=size;i++) for(j=1;j<=size;j++) map[i][j] = ' '; digui(n,1,1); for(i=1;i<=size;i++) { for(j=1;j<=size;j++) cout<<map[i][j]; cout<<endl; } cout<<"-"<<endl; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator