POJ-2083 Fractal-X星阵图
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 :
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
1
2
3
4
-1
Examples
Input
3
2 3 2
2
3 2
2 3
Output
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
-
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 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
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 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 X
-
Analysis
一句话题意:打印图形
其实就是把删一个图形在右上、左下、右下分别复制粘贴一遍就OK了
然而我居然习惯输出空格导致WA了3发。。。
代码
真的很水啦。。。
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstdio>
#include<cstring>
using namespace std;
int n,cnt[100];
char co[1000][1000];
void copy(int k,int x,int y){
for(int j=1;j<=cnt[k-1];j++){
for(int l=cnt[k-1]*2+1;l<=cnt[k];l++){//右上
co[j][l]=co[j][l-cnt[k-1]*2];
}
}
for(int j=cnt[k-1]+1;j<=cnt[k-1]*2;j++){//中间
for(int l=cnt[k-1]+1;l<=cnt[k-1]*2;l++){
co[j][l]=co[j-cnt[k-1]][l-cnt[k-1]];
}
}
for(int j=cnt[k-1]*2+1;j<=cnt[k];j++){//左下
for(int l=1;l<=cnt[k-1];l++){
co[j][l]=co[j-cnt[k-1]*2][l];
}
}
for(int j=cnt[k-1]*2+1;j<=cnt[k];j++){//右下
for(int l=cnt[k-1]*2+1;l<=cnt[k];l++){
co[j][l]=co[j-cnt[k-1]*2][l-cnt[k-1]*2];
}
}
}
int main(){
cnt[0]=cnt[1]=1;
for(int i=2;i<=10;i++)cnt[i]=cnt[i-1]*3;
while(cin>>n){
memset(co,' ',sizeof(co));
if(n==-1)return 0;
co[1][1]='X';
for(int i=2;i<=n;i++){
copy(i,cnt[i],cnt[i]);
}
for(int i=1;i<=cnt[n];i++){
for(int j=1;j<=cnt[n];j++){
cout<<co[i][j];
}
cout<<endl;
}
cout<<"-"<<endl;
}
}
POJ-2083 Fractal-X星阵图的更多相关文章
- POJ 2083 Fractal 分形题目
这两天自学了一线算法导论里分治策略的内容,秉着只有真正投入投入编程,才能更好的理解一种算法的思想的想法,兴致勃勃地找一些入门的题来学习. 搜了一下最后把目光锁定在了Poj fractal这一个题上.以 ...
- poj 2083 Fractal 递归 图形打印
题目链接: http://poj.org/problem?id=2083 题目描述: n = 1时,图形b[1]是X n = 2时,图形b[2]是X X X ...
- POJ 2083 Fractal
Fractal Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 6646 Accepted: 3297 Descripti ...
- POJ 2083 Fractal 分形
去年校赛团队赛就有一道分形让所有大一新生欲生欲死…… 当时就想学了 结果一直拖到…… 今天上午…… 马上要省选了 才会一点基础分形…… 还是自己不够努力啊…… 分形主要是要找到递归点…… 还有深度…… ...
- ( 递归 )Fractal -- POJ -- 2083
http://poj.org/problem?id=2083 Fractal Time Limit: 1000MS Memory Limit: 30000K Total Submissions: ...
- POJ 1985.Cow Marathon-树的直径-树的直径模板(BFS、DFS(vector存图)、DFS(前向星存图))
Cow Marathon Time Limit: 2000MS Memory Limit: 30000K Total Submissions: 7536 Accepted: 3559 Case ...
- UESTC30-最短路-Floyd最短路、spfa+链式前向星建图
最短路 Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) 在每年的校赛里,所有进入决赛的同 ...
- 最短路 spfa 算法 && 链式前向星存图
推荐博客 https://i.cnblogs.com/EditPosts.aspx?opt=1 http://blog.csdn.net/mcdonnell_douglas/article/deta ...
- HDU 1535 SPFA 前向星存图优化
Invitation Cards Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...
随机推荐
- Go语言获取系统性能数据gopsutil库
psutil是一个跨平台进程和系统监控的Python库,而gopsutil是其Go语言版本的实现.本文介绍了它的基本使用. Go语言部署简单.性能好的特点非常适合做一些诸如采集系统信息和监控的服务,本 ...
- kafka入门配置
问题导读: 1.zookeeper在kafka的作用是什么? 2.kafka中几乎不允许对消息进行“随机读写”的原因是什么? 3.kafka集群consumer和producer状态信息是如何保存的? ...
- springboot 定时器 Schdule
定时器:定时启动任务,执行代码 1.在启动类中加入注解: 2.创建一个类,并且在这个类上加入注解:@Component 3.定义一个方法,在方法上加入注解:@Scheduled(cron=" ...
- charles 帮助菜单总结
本文参考:charles 帮助菜单总结 charles的window和help的菜单介绍 其中window菜单的如下 这里我一般用到的就是 Active connections:可以用它来看charl ...
- response对响应的设置
1.response对象设置响应行状态码: protected void doGet(HttpServletRequest request, HttpServletResponse response) ...
- switch对输入的运算符的判断
import java.util.*; public class App3 { public static void main(String [] args) { int num1,num2,num; ...
- php装上sqlserver驱动后仍然显示Call to undefined function sqlsrv_connect()问题
今天老师要求本来的php+mysql改为php+sqlserver,在网上搜索了相应的教程,说是“需要下载安装Microsoft Drivers for PHP for SQL Server驱动”,下 ...
- JsonConvert 转DateTime类型为json 带T
在调用接口的时候 将Model转换成json Datetime类型多了个T 用的是Newtonsoft.Json.dll 版本v4.5.0.0 代码:paramsjson = JsonConvert ...
- 删除mac开机启动项
1、开“系统偏好设置”窗口,选择“用户与群组”,进入用户与群组窗口.选择登录项选项卡,再解锁,最后删除开机启动的应用. 2、分别在以下6个目录中检查是否有与anydesk相关的plist文件 ~/ ...
- 更改hadoop集群yarn的webui中的开始时间和结束时间为本地时间
yarn集群的webui地址为:http://rm:8088 执行任务后,任务的开始时间和结束时间都是utc时间,查看很不方便. 查找相关资料发现hadoop有补丁包,补丁地址:https://iss ...