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 ...
随机推荐
- 在JSP页面用EL表达式获取数据
<h4>获取域对象中的值</h4><% request.setAttribute("name", "射雕英雄传"); ...
- html5表单与Jquery Ajax配合使用
html5的表单控件提供了很多格式检测功能,可以省去很多烦人的javascript验证代码,例如pattern属性和require属性,但触发的条件是表单提交,如果想通过ajax提交表单,就出现了不能 ...
- HTML连载38-内边距属性、外边距属性
一.内边距属性 1.定义:边框和内容之间的距离就是内边距 2.分开写 padding-top:数字px: padding-left:数字px: padding-bottom:数字px: padding ...
- 48 (OC)* 适配iPad和iPhone、以及横竖屏适配。
一:核心方法 1.三个方法 1.1:开始就会触发 - (void)viewWillLayoutSubviews; 1.2:开始就会触发 - (void)viewDidLayoutSubviews; 1 ...
- [VB.NET Tips]ParamArray参数数组
ParamArray参数数组,可以理解为传递给方法的多余的参数全都存放在这个数组中. ParamArray只能是ByVal按值传递,不能是可选参数,而且只能做为方法定义的最后一个参数. 非常类似于Py ...
- BOM之本地数据存储
JavaScript中本地存储数据常用的,且兼容性较好的有两种方式,cookie和Storage.另外还可以使用location.hash临时存储少量关键信息. 一 location.hash ...
- ActiveMQ高级特性
一.常用配置属性 以下配置文件目录均为:${activemq_home}/conf/activemq.xml 1.定期扫描清理 ActiveMQ中有一项功能:Delete Inactive Desti ...
- asp.net core IdentityServer4 概述
概览 现代应用程序看上去大都是这样的: 最常见的交互是: 浏览器与Web应用程序通信 Web应用程序与Web API通信(有时是独立的,有时是代表用户的) 基于浏览器的应用程序与Web API通信 本 ...
- SpringBootSecurity学习(03)网页版登录添加自定义登录页面
自定义登录页面 前面无论是使用默认配置,还是自定义配置类,都是使用的springboot-security自带的登录页面,自带的登录页面在这个版本虽然设计的非常不错,但是在实际开发中,我们通常还是使用 ...
- 品Spring:bean工厂后处理器的调用规则
上一篇文章介绍了对@Configuration类的处理逻辑,这些逻辑都写在ConfigurationClassPostProcessor类中. 这个类不仅是一个“bean工厂后处理器”,还是一个“be ...