哈理工OJ 2291 Help C5(分形题目)
来源:互联网 发布:基础地理数据 编辑:程序博客网 时间:2024/04/29 06:05
题目链接:http://acm.hrbust.edu.cn/index.php?m=ProblemSet&a=showProblem&problem_id=2291
Help C5
Time Limit: 1000 MS Memory Limit: 65535 K
Total Submit: 170(39 users) Total Accepted: 50(37 users) Rating: Special Judge: No
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
上面的图形和原题中不符,建议去原题中看图形------------------------------------------ -------------------------------------下面是AC代码:
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;char a[3000][3000];int mypow(int n){ int ans=1; for(int i=1; i<=n; i++) { ans=ans*3; } return ans;}void dfs(int cur,int x,int y){ if(cur==1) { a[x][y]='C'; return ; } int s=mypow(cur-2); dfs(cur-1,x,y+s); dfs(cur-1,x,y+2*s); dfs(cur-1,x+s,y); dfs(cur-1,x+2*s,y+s); dfs(cur-1,x+2*s,y+2*s);}int main(){ int t; scanf("%d",&t); while(t--) { int n; memset(a,' ',sizeof(a)); scanf("%d",&n); dfs(n+1,1,1); int s=mypow(n); for(int i=1; i<=s; i++) { for(int j=s;j>=1;j--) if(a[i][j]=='C') { a[i][j+1]='\0';//去除每行里面多余的空格 break; } } for(int i=1; i<=s; i++) { printf("%s\n",a[i]+1);//从每行的第二个开始输出 } } return 0;}
- 哈理工OJ 2291 Help C5(分形题目)
- 哈理工OJ 2147 经理办公室(深搜题目)
- 哈理工OJ 2161 数列(数学题目)
- 哈理工OJ 2074 逃生(广搜题目)
- 哈理工OJ 1909 理工门外的树(思维题目)
- 哈理工OJ 2134 分拆素数和(简单题)
- 哈理工OJ 2281 11(简单的找规律题目)
- 哈理工OJ 2248 开锁魔法1(简单的思维题目)
- 哈理工OJ 1151 追求(斐波那契变形【思维题目】)
- 哈理工OJ 2255 镇守府海域·镇守府近海(模拟题目)
- 取石子(一) (南阳理工oj 题目23)
- 括号配对问题 (南阳理工oj-题目2)
- 一种排序 (南阳理工oj 题目8)
- Registration system (南阳理工oj 题目991)
- 01串 (南阳理工oj 题目252)
- 子串和(南阳理工oj-题目44)
- 笨小熊(南阳理工oj 题目62)
- 分形 递归打印之C5
- 【第四次自考】实战总结
- C# SQL带传入、输出参数及返回值的存储过程
- 使用WINDOW批处理更新本地所有SVN目录
- Adapter总结
- 机器学习中的超平面
- 哈理工OJ 2291 Help C5(分形题目)
- 1015. Reversible Primes (20)
- mysql之登录
- 读书笔记--灵性
- CentOS、Ubuntu、Debian三个linux比较异同
- [Toddler's Bottle]fd
- C++学习笔记56——类模板中的class与typename
- 学习
- 关于 AVPlayer的总结-1