欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

POJ-1941 The Sierpinski Fractal

发布时间:2024/10/12 编程问答 39 豆豆
生活随笔 收集整理的这篇文章主要介绍了 POJ-1941 The Sierpinski Fractal 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

题意:如图所示画出图形。

 

思路:递归~

题目连接:http://poj.org/problem?id=1941

 

View Code 1 #include <cstdio> 2 #include <cstring> 3 #include <cstdlib> 4 #include <cmath> 5 #include <string> 6 #include <algorithm> 7 #include <iostream> 8 using namespace std; 9 const int N=3000; 10 11 char map[N][N]; 12 13 void dfs(int n,int x,int y){ 14 if(n==1){ 15 map[x][y]=map[x-1][y+1]='/'; 16 map[x][y+1]=map[x][y+2]='_'; 17 map[x][y+3]=map[x-1][y+2]='\\'; 18 return ; 19 } 20 int size=1<<(n-1); 21 dfs(n-1,x,y); 22 dfs(n-1,x-size,y+size); 23 dfs(n-1,x,y+2*size); 24 } 25 26 int main(){ 27 28 // freopen("data.in","r",stdin); 29 // freopen("data.out","w",stdout); 30 31 int n; 32 while(scanf("%d",&n),n){ 33 memset(map,' ',sizeof(map)); 34 int size=1<<n; 35 dfs(n,size,1); 36 for(int i=1;i<=size;i++){ 37 for(int j=1;j<=size*2;j++) 38 printf("%c",map[i][j]); 39 puts(""); 40 } 41 puts(""); 42 } 43 return 0; 44 }

 

转载于:https://www.cnblogs.com/Hug-Sea/articles/2527097.html

总结

以上是生活随笔为你收集整理的POJ-1941 The Sierpinski Fractal的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。