poj 2083 Fractal 【递归打印字符】
来源:互联网 发布:mysql 删除重复 编辑:程序博客网 时间:2024/05/14 16:03
Fractal
Time Limit: 1000MS Memory Limit: 30000KTotal Submissions: 8356 Accepted: 3972
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-
题意:打印字符,很有意思的题目吧。
思路:先填满空格,最后递归打印就好了。
写的代码有点渣。。。
AC代码:
#include <cstdio>#include <cstring>#include <cmath>#include <cstdlib>#include <algorithm>#include <queue>#include <stack>#include <map>#include <set>#include <vector>#define INF 0x3f3f3f#define eps 1e-8#define MAXN (2000+10)#define MAXM (100000)#define Ri(a) scanf("%d", &a)#define Rl(a) scanf("%lld", &a)#define Rf(a) scanf("%lf", &a)#define Rs(a) scanf("%s", a)#define Pi(a) printf("%d\n", (a))#define Pf(a) printf("%.2lf\n", (a))#define Pl(a) printf("%lld\n", (a))#define Ps(a) printf("%s\n", (a))#define W(a) while(a--)#define CLR(a, b) memset(a, (b), sizeof(a))#define MOD 1000000007#define LL long long#define lson o<<1, l, mid#define rson o<<1|1, mid+1, r#define ll o<<1#define rr o<<1|1using namespace std;char str[MAXN][MAXN];int Pow(int a, int b){ int ans = 1; while(b--) ans *= a; return ans;}void getmap(int r1, int c1, int r2, int c2, int n)//在左上角(r1, c1) 右下角(r2, c2)的矩形区域内打印字符{ if(n == 1) { str[r1][c1] = 'X'; return ; } int op = Pow(3, n-2); getmap(r1, c1, r1+op-1, c1+op-1, n-1); getmap(r1, c1+op-1+op+1, r1+op-1, c1+op-1+op+1+op-1, n-1); getmap(r1+op, c1+op, r1+op+op-1, c1+op+op-1, n-1); getmap(r1+op-1+op+1, c1, r1+op-1+op+1+op-1, c1+op-1, n-1); getmap(r1+op+op, c1+op+op, r1+op+op+op-1, c1+op+op+op-1, n-1);}int main(){ int n; while( Ri(n), n != -1) { int M = Pow(3, n-1); CLR(str, 0); for(int i = 0; i < M; i++) for(int j = 0; j < M; j++) str[i][j] = ' '; getmap(0, 0, M-1, M-1, n); for(int i = 0; i < M; i++) printf("%s\n", str[i]); printf("-\n"); } return 0;}
0 0
- poj 2083 Fractal 【递归打印字符】
- 【递归】poj 2083fractal
- poj 2083 Fractal 递归
- POJ 2083 Fractal 递归
- (简单递归3.4.1)POJ 2083 Fractal(分形图的打印)
- POJ 2083 Fractal 分治+递归
- POJ 2083 Fractal 递归画分形
- POJ 2083 Fractal(递归)
- poj 1941 The Sierpinski Fractal(递归打印图形)
- poj 2083 Fractal 纯递归,挺好, 我的版本
- POJ—2083—Fractal—【递归与分治】
- poj 2083 Fractal 分形基本方法( 总结) 递归
- Poj 2083 Fractal
- POJ-2083-Fractal
- POJ 2083 Fractal
- Fractal poj 2083
- POJ 2083 Fractal
- poj 2083 Fractal
- 分布式process总结之二:Mutual Exclusion
- 沙盒路径的结构
- 跳转到WEB-INF目录下的文件和页面之间参数传递
- HDU5586 - Sum (最大子列和)
- android焦点分发无法获取到Down事件,却有Move和Up
- poj 2083 Fractal 【递归打印字符】
- lua字符串的分割函数
- CoreData: error: Failed to call designated initializer on NSManagedObject 的解决方法
- 数据结构C++语言描述专题系列 (四) 链式栈和队列
- 关于计算机视觉(随谈)
- Maven教程-坐标和依赖
- HDU5510 - Bazinga (kmp+暴力)
- 1008.数组元素循环右移问题
- Codeforces 601A Dijkstra最短路