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 ...
随机推荐
- java8函数式接口详解、函数接口详解、lambda表达式匿名函数、方法引用使用含义、函数式接口实例、如何定义函数式接口
函数式接口详细定义 函数式接口只有一个抽象方法 由于default方法有一个实现,所以他们不是抽象的. 如果一个接口定义了一个抽象方法,而他恰好覆盖了Object的public方法,仍旧不算做接口的抽 ...
- 百度地图WEB端判断用户是否在网格范围内
在pc端设置商家的配送范围,用户在下单时,根据用户设置的配送地点判断是否在可配送范围内,并给用户相应的提示. 下面说下我的实现思路: 1.用百度地图在PC端设置配送范围,可拖拽选择 2.根据用户设置的 ...
- 使用gcc不同选项来编译查看中间生成文件
gcc编译C程序的总体流程如下图 用到的命令如下: .c---> .i gcc -E hello.c .c--->.s gcc -S hello.c .c--->.o gcc -c ...
- 一套基于SpringBoot+Vue+Shiro 前后端分离 开发的代码生成器
一.前言 最近花了一个月时间完成了一套基于Spring Boot+Vue+Shiro前后端分离的代码生成器,目前项目代码已基本完成 止步传统CRUD,进阶代码优化: 该项目可根据数据库字段动态生成 c ...
- linux切换jdk
一.安装openjdk yum search openjdk yum install java-1.8.0-openjdk-devel-debug.x86_64 二.查询java版本 alternat ...
- [Code] 变态之人键合一
目的也比较单纯,选一门语言,走向人键合一. 选了两本书作为操练场:<精通Python设计模式>.<Data Structure and Algorithm in Python> ...
- Centos6安装MySQL5.7(yum方式)
1. 下载并安装用来配置mysql的yum源的rpm包 # 下载 wget http://repo.mysql.com/mysql57-community-release-el6-10.noarch. ...
- CDH集群的时间同步--简要配置要求
每个节点执行ntpstat 和 timedatectl 都显示同步并且时间相同,那么CDH才能正常使用.每次ntp服务同步到外部授时中心都要一段时间(5~10分钟),只有当NTP server(nod ...
- Spring boot 官网学习笔记 - 开发第一个Spring boot web应用程序(使用mvn执行、使用jar执行)
Creating the POM <?xml version="1.0" encoding="UTF-8"?> <project xmlns= ...
- pyinstaller程序打包工具
PyInstaller是一个能将Python程序转换成单个可执行文件的程序, 操作系统支持Windows, Linux, Mac OS X, Solaris和AIX.并且很多包都支持开箱即用,不依赖环 ...