SDKD 14级组队练习赛(一) J 递归打印图案
来源:互联网 发布:网络护卫怎么卡cf手游 编辑:程序博客网 时间:2024/05/19 21:43
Description
A fractal is an object or quantity that displays self-similarity, in a somewhat technical sense, on all scales. The object need not exhibit exactly the same structure at all scales, but the same "type" of structures must appear on all scales.
A Sierpinski fractal is defined as below:
@
@@@
B(n-1)B(n-1)B(n-1)
Your task is to draw a Sierpinski fractal of degree n.
Input
The input consists of several test cases. Each line of the input contains a positive integer n which is no greater than 10. The last line of input is an integer 0 indicating the end of input.
Output
For each test case, output the Sierpinski fractal using the '@' notation. Print a blank line after each test case.Don't output any trailing spaces at the end of each line, or you may get a PE!
Sample Input
120
Sample Output
@
@
@@
瑞神的代码,自己太水了,刚学会递归。。。。
@
@@
瑞神的代码,自己太水了,刚学会递归。。。。
#include<cstdio>#include<cstring>using namespace std;const int inf=0x3f3f3f3f;const int maxn=1030;char g[maxn][maxn];void draw(int n,int l1,int l2,int r1,int r2){ if(n==1){g[l1][r1]='@';return;} int k=1<<(n-2); draw(n-1,l1,l1+k,r1,r1+k); draw(n-1,l2-k,l2,r1,r1+k); draw(n-1,l2-k,l2,r2-k,r2); return;}int main(){ int n; while(~scanf("%d",&n)&&n){ memset(g,' ',sizeof(g)); draw(n,0,1<<(n-1),0,1<<(n-1)); int k=1<<(n-1); for(int i=0;i<k;++i){ for(int j=k-1;j>=0;--j) if(g[i][j]=='@') {g[i][j+1]=0;break;} puts(g[i]); } puts(""); } return 0;}
0 0
- SDKD 14级组队练习赛(一) J 递归打印图案
- SDKD 14级组队练习赛(一) D 数组存储二叉树并递归遍历
- *号图案打印练习一
- *号图案打印练习二
- nyist -- 组队赛(一)
- 总结(组队练习)
- 递归练习(一)
- 递推递归练习 J
- 递推递归练习J
- 《递归递推练习》J
- 递归递推练习 J
- 递归递推练习 J
- 130721UVA组队练习赛
- 组队赛(一)F - Low Power
- 打印图案(A-G)
- 【每周一题】4、打印金字塔图案
- 递推递归练习 J 数学黑洞
- 递推递归练习J数学黑洞
- jquery用户自定义选择器及选择器高级用法实验
- 毕设(排课系统)笔记1---用户注册(二)
- JAVA程序设计基础教程 异常处理
- 输出一个学生的成绩数组,该数组中有五个学生的数据记录
- 使用TextView显示图像添加链接的方法
- SDKD 14级组队练习赛(一) J 递归打印图案
- 2015山东省赛B题-sdut3252---Lowest Unique Price
- Fedora13下真正能用的源(2015-5-16亲测)
- 回溯法:八皇后问题
- spring mvc 多视图配置
- POJ 3669 Meteor Shower
- [leetcode][math] Plus One
- 20150517
- Android中使用Gson解析JSON数据的两种方法