poj Fractal 2083 (模拟&&dfs)
来源:互联网 发布:泛雅网络教学平台页面 编辑:程序博客网 时间:2024/06/06 03:57
Fractal
Time Limit: 1000MS Memory Limit: 30000KTotal Submissions: 8339 Accepted: 3963
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 box fractal is defined as below :
Your task is to draw a box fractal of degree n.
A box fractal is defined as below :
- A box fractal of degree 1 is simply
X - A box fractal of degree 2 is
X X
X
X X - If using B(n - 1) to represent the box fractal of degree n - 1, then a box fractal of degree n is defined recursively as following
B(n - 1) B(n - 1) B(n - 1)B(n - 1) B(n - 1)
Your task is to draw a box 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 7. The last line of input is a negative integer −1 indicating the end of input.
Output
For each test case, output the box fractal using the 'X' notation. Please notice that 'X' is an uppercase letter. Print a line with only a single dash after each test case.
Sample Input
1234-1
Sample Output
X-X X XX X-X X X X X XX X X X X X X X XX X X X X XX X X X-X X X X X X X X X X X XX X X X X X X X X X X X X X X X X XX X X X X X X X X X X XX X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X XX X X X X X X X X X X XX X X X X X X X X X X X X X X X X XX X X X X X X X X X X XX X X X X X X X-
Source
大神的思路及分析,,。。。
/*n度的盒分形的规模为3^(n-1),即n度的盒分形图为一个长宽为3^(n-1)的正方形。
设置递归函数printBox(n,x,y)生成以坐标(x,y)为左上角的n度盒分形。
1)递归边界: 若n=1,则在(x,y)输出‘X’
2)若n>1,则计算n-1度的盒子的规模 m = 3^(n-2),分别在左上方, 右上方,中间,左下方和右下方画出5个n-1度的盒子。
对于左上方的n-1度的盒子,左上角的坐标为(x,y),递归printBox(n-1,x,y)生成;
对于右上方的n-1度的盒子,左上角的坐标为(x+2m,y),递归printBox(n-1,x+2m,y)生成;
对于中间的n-1度的盒子,左上角的坐标为(x+m,y+m),递归printBox(n-1,x+m,y+m)生成;
对于左下方的n-1度的盒子,左上角的坐标为(x,y+2m),递归printBox(n-1,x,y+2m)生成;
对于右上方n-1度的盒子,左上角的坐标为(x+2m,y+2m),递归printBox(n-1,x+2m,y+2m)生成;
#include<stdio.h>#include<string.h>#include<math.h>#include<algorithm>#define N 1010using namespace std;char map[N][N];void cop(int n,int x,int y){if(n==1)map[x][y]='X';else{int m=pow(3,n-2);cop(n-1,x,y);cop(n-1,x+2*m,y);cop(n-1,x,y+2*m);cop(n-1,x+m,y+m);cop(n-1,x+2*m,y+2*m);}}int main(){int n,i,j;while(scanf("%d",&n)&&n!=-1){int m=pow(3,n-1);for(i=0;i<m;i++){for(j=0;j<m;j++){map[i][j]=' ';map[i][m]='\0';}}cop(n,0,0);for(i=0;i<m;i++)printf("%s\n",map[i]);printf("-\n");}return 0;}
0 0
- poj Fractal 2083 (模拟&&dfs)
- POJ 2083 Fractal(dfs)
- poj--2083--Fractal(dfs)
- poj 2083 Fractal (dfs 分形图)
- 10609 - Fractal (模拟,dfs)
- POJ 2083 Fractal(递归)
- POJ 题目2083 Fractal(分治)
- POJ 2083 Fractal (打表乱搞)
- POJ 2083 Fractal(分形题目)
- Poj 2083 Fractal
- 【递归】poj 2083fractal
- POJ-2083-Fractal
- poj 2083 Fractal 递归
- POJ 2083 Fractal
- Fractal poj 2083
- POJ 2083 Fractal 递归
- POJ 2083 Fractal
- poj 2083 Fractal
- poj Repeater 3768 (模拟&&dfs) 好题
- HDOJ 5289 Assignment 【RMQ 二分 || 单调队列】
- android html解析
- cmd正则表达式批量重命名
- 容器的同步控制与只读设置JAVA133
- poj Fractal 2083 (模拟&&dfs)
- CSU 1553 线段树+尺取法
- java设计模式(四)—工厂模式
- 容器(一):队列容器List
- 电信用户分群精准画像的7个步骤
- HDU 1114 Piggy-Bank (完全背包)
- Linux Kernel List
- ARM_s5pv210_arm_9
- Qt 设置程序图标