标签:
Description
/
/__\
Input
Output
Sample Input
3
2
1
0
Sample Output
/ /__ /\ / /__\/__ /\ / /__\ /__ /\ /\ /\ //__\/__\/__\/__
/ /__ /\ //__\/__
//__
Hint
Source
1 //It is made by jump~ 2 #include <iostream> 3 #include <cstdlib> 4 #include <cstring> 5 #include <cstdio> 6 #include <cmath> 7 #include <algorithm> 8 #include <ctime> 9 #include <vector> 10 #include <queue> 11 #include <map> 12 #include <set> 13 using namespace std; 14 typedef long long LL; 15 char ch[2048][2048]; 16 int n; 17 18 inline int getint() 19 { 20 int w=0,q=0; char c=getchar(); 21 while((c<‘0‘ || c>‘9‘) && c!=‘-‘) c=getchar(); if(c==‘-‘) q=1,c=getchar(); 22 while (c>=‘0‘ && c<=‘9‘) w=w*10+c-‘0‘, c=getchar(); return q ? -w : w; 23 } 24 25 inline void solve(int x,int y,int now){ 26 if(now==1) { 27 ch[x][y]=‘/‘; ch[x][y+1]=‘_‘; ch[x][y+2]=‘_‘; ch[x][y+3]=‘\\‘; 28 ch[x-1][y+1]=‘/‘; ch[x-1][y+2]=‘\\‘; 29 return ; 30 } 31 int du=(1<<now);//拆分成三个小三角形 32 solve(x,y,now-1); solve(x,y+du,now-1); solve(x-du/2,y+du/2,now-1); 33 } 34 35 inline void work(){ 36 while(1) { 37 n=getint(); if(n==0) break; 38 memset(ch,0,sizeof(ch)); int mi=(1<<n); 39 solve(mi,0,n); int last;//记录最后一个 40 for(int i=1;i<=mi;i++) { 41 for(int j=0;j<mi*2;j++) if(ch[i][j]) last=j; 42 for(int j=0;j<last;j++) if(!ch[i][j]) ch[i][j]=‘ ‘; 43 } 44 for(int i=1;i<=mi;i++) printf("%s\n",ch[i]); 45 printf("\n"); 46 } 47 } 48 49 int main() 50 { 51 work(); 52 return 0; 53 }
POJ1941 The Sierpinski Fractal
标签:
原文地址:http://www.cnblogs.com/ljh2000-jump/p/5883295.html