分形 递归打印之C5
2016-03-11 16:53
363 查看
Help C5 | ||||||
| ||||||
Description | ||||||
Hello, I’m Sea5, and you can call me C5 instead. I want a program which can sign my name automatically. And my brothers, C0, C1, C2, C3, C4, C6, C7, C8, each of them wants one as well. Can you help us? | ||||||
Input | ||||||
First line is the number of test cases T(T<=8). T lines follow, each line includes an integer N(N<=7), and you should help C(N) to sign his name. | ||||||
Output | ||||||
C0’s signature is ‘C’. When you draw C(N)’s name, you should print the name using C(N-1)’s name as its element, and using the following format to draw it. *XX X** *XX (X is the element, * is blank space) And please don’t print extra spaces at the end of line. For example, C1’s name should be *CC *CC C C** *CC But not *CC (I use * to show you where are spaces.) | ||||||
Sample Input | ||||||
3 0 1 2 | ||||||
Sample Output | ||||||
C CC C CC CC CC C C CC CC CC C CC CC CC C C CC CC #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<cmath> using namespace std; #define MAX 10005 char map[MAX][MAX]; int n; void fx(int n, int x, int y) { if(n==0) { map[x][y]='C'; return; } if(n==1) { //map[x][y]=map[x+2][y]=' '; map[x][y+1]=map[x][y+2]=map[x+1][y]=map[x+2][y+1]=map[x+2][y+2]='C'; //注意竖向为x轴, 横向为y轴; return ; } else { int m=pow(3, (n-1)); //m为上一次C分形度 //fx(n-1, x, y); //本想递归空格,结果不用递归空格,却递归成C了; fx(n-1, x, y+m); fx(n-1, x, y+2*m); fx(n-1, x+m, y); //fx(n-1, x+2*m, y); fx(n-1, x+2*m, y+m); fx(n-1, x+2*m, y+2*m); } } int main() { int t; scanf("%d", &t); for(int i=0; i<t; i++) { scanf("%d", &n); int size=pow(3, (n)); //size为当前分形度; for(int i=0; i<size; i++) { for(int j=0; j<size; j++) { map[i][j]=' '; map[i][size]='\0'; //初始化map[][]; } } fx(n, 0, 0); for(int i=0; i<size; i++) { for(int j=size-1; j>=0; j--) //倒序查C,再加'\0'; { if(map[i][j]=='C'){ map[i][j+1]='\0'; //防止最后一个C后有空格; break; } } } for(int i=0; i<size; i++) { printf("%s\n", map[i]); } } return 0; } |
相关文章推荐
- “铺地砖”问题
- 分形图(fractal pictures)
- Mandelbrot Set & Julia Set -- 美丽分形 (C++, MFC + BCG + CxImage 实现)
- poj1760 Disk Tree
- 谢宾斯基三角形
- Sierpinski三角
- 树动画
- 分形--Cantor三分集
- 天梯赛 L1-002. 打印沙漏
- 基于复变函数f(z)=z^2+c的迭代分形图
- 分形 递归打印之神奇三角形
- 用Qt绘制一张分形图
- 哈理工OJ 2308 Invitations(分形题目)
- 分形小记
- 分形神经网络
- 曼德勃罗集(Mandelbrot Set)
- 分形与计算机图形学
- Step 7:Processing分形之二——Peter de Jong Attractor
- Step 6:Processing分形之一——Wallpaper
- POJ 3768(分形+递归)