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星阵图的更多相关文章

  1. POJ 2083 Fractal 分形题目

    这两天自学了一线算法导论里分治策略的内容,秉着只有真正投入投入编程,才能更好的理解一种算法的思想的想法,兴致勃勃地找一些入门的题来学习. 搜了一下最后把目光锁定在了Poj fractal这一个题上.以 ...

  2. poj 2083 Fractal 递归 图形打印

    题目链接: http://poj.org/problem?id=2083 题目描述: n = 1时,图形b[1]是X n = 2时,图形b[2]是X  X        X               ...

  3. POJ 2083 Fractal

    Fractal Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 6646   Accepted: 3297 Descripti ...

  4. POJ 2083 Fractal 分形

    去年校赛团队赛就有一道分形让所有大一新生欲生欲死…… 当时就想学了 结果一直拖到…… 今天上午…… 马上要省选了 才会一点基础分形…… 还是自己不够努力啊…… 分形主要是要找到递归点…… 还有深度…… ...

  5. ( 递归 )Fractal -- POJ -- 2083

    http://poj.org/problem?id=2083 Fractal Time Limit: 1000MS   Memory Limit: 30000K Total Submissions:  ...

  6. POJ 1985.Cow Marathon-树的直径-树的直径模板(BFS、DFS(vector存图)、DFS(前向星存图))

    Cow Marathon Time Limit: 2000MS   Memory Limit: 30000K Total Submissions: 7536   Accepted: 3559 Case ...

  7. UESTC30-最短路-Floyd最短路、spfa+链式前向星建图

    最短路 Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) 在每年的校赛里,所有进入决赛的同 ...

  8. 最短路 spfa 算法 && 链式前向星存图

    推荐博客  https://i.cnblogs.com/EditPosts.aspx?opt=1 http://blog.csdn.net/mcdonnell_douglas/article/deta ...

  9. HDU 1535 SPFA 前向星存图优化

    Invitation Cards Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others ...

随机推荐

  1. 基于SSM后台管理系统/人事管理系统

    今天给大家分享一个基于SpringMVC+Mybatis+Mysql的后台管理系统,顾名思义,一个系统一般分为前台和后台,前台主要面向用户,而后台主要面向的则是管理员,后台和前台有所不同,后台的业务一 ...

  2. netcore 基于 DispatchProxy 实现一个简单Rpc远程调用

    前言 netcore 发布以来,一直很关注netcore的进程.目前在公司负责的网站也历经波折的全部有.net framework 4.0 全部切换到netcore 2.2 版本中.虽然过程遇到的坑不 ...

  3. ScrollView内嵌ViewPager导致ViewPager滑动困难问题

    转自:http://titanseason.iteye.com/blog/1858874 解决方式:重写ScrollView,然后在xml中定义布局的时候,使用自定义的PagerScrollView而 ...

  4. linux下tomcat无法远程访问(开放8080端口)

    我们在linux下配置了tomcat后发现,无法访问除了linux(如果是虚拟机的话,宿主机子根本无法访问tomcat),解决下吧 原因是我们的tomcat访问需要8080端口,但是从外部访问,我们的 ...

  5. Spring boot 自定义banner的在线制作

    目前工作不是很忙,利用闲暇的时间,在给自己不断地充电,提升自己的技术实力. 目前在做一个基于Spring Boot2.x+webmagic+quartz的爬虫项目[hotDog]https://git ...

  6. vue-cli+webpack打包,上线

    1.先修改配置文件再打包.有些人打包后运行一片空白,主要是由于路径问题 所以首先需要修改config下的index.js配置文件 上图中第一个要修改的就是静态文件的路径,打包后静态文件就在当前目录下, ...

  7. springcloud config配置读取优先级

    情景描述 最近在修复Eureka的静态页面加载不出的缺陷时,最终发现是远程GIT仓库将静态资源访问方式配置给禁用了(spring.resources.add-mappings=false).虽然最后直 ...

  8. activity的隐式和显式启动

    显式Intent(Explicit intent):通过指定Intent组件名称来实现的,它一般用在知道目标组件名称的前提下,一般是在相同的应用程序内部实现的. 隐式Intent(Implicit i ...

  9. 推荐5款自学手机APP,请低调收藏,让你变得越来越优秀

    现在的手机APP真的是太多了,但里面的功能同类性又非常大,很难找到实用并且符合要求的APP.接下来就为小伙伴们推荐5款非常实用的APP软件,保证你会爱不释手,轻松秒变手机达人. 1.清爽视频编辑器 一 ...

  10. 数据分析--Matplotlib的基本使用

    一.Matplotlib概述 1.Matplotlib是一个强大的Python绘图和数据可视化的工具包. 2.python中操作方式: 安装方法:pip install matplotlib 引用方法 ...