Time Limit: 1000MS   Memory Limit: 30000KB   64bit IO Format: %I64d & %I64u

Submit
Status

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

Sample 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
- 输入的数表示的其实就是有几大层,在dfs里设置的五个语句,可以表示逐层查找,而第n层的元素是n-1层的,看图就知道,逐个找到,左上角的‘X’,
然后在递归中将每一层遍历出来,列个表会好一些
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
char map[1010][1010];
int POW(int n,int m)
{
int ans=1;
for(int i=1;i<=m;i++)
ans*=n;
return ans;
}
void dfs(int n,int x,int y)
{
if(n==1)
{
map[x][y]='X';
return ;
}
int ans=POW(3,n-2);
dfs(n-1,x,y);
dfs(n-1,x,y+(ans<<1));
dfs(n-1,x+ans,y+ans);
dfs(n-1,x+(ans<<1),y);
dfs(n-1,x+(ans<<1),y+(ans<<1));
}
int main()
{
int n;
while(scanf("%d",&n),n!=-1)
{
int ans=POW(3,n-1);
for(int i=0;i<ans;i++)
{
for(int j=0;j<ans;j++)
{
map[i][j]=' ';
}
}
dfs(n,0,0);
for(int i=0;i<ans;i++)
{
map[i][ans]='\n';
printf("%s",map[i]);
}
printf("-\n");
}
return 0;
}

poj--2083--Fractal(dfs)的更多相关文章

  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.3172 Scales (DFS)

    POJ.3172 Scales (DFS) 题意分析 一开始没看数据范围,上来直接01背包写的.RE后看数据范围吓死了.然后写了个2^1000的DFS,妥妥的T. 后来想到了预处理前缀和的方法.细节以 ...

  7. ACM : POJ 2676 SudoKu DFS - 数独

    SudoKu Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu POJ 2676 Descr ...

  8. ACM/ICPC 之 分治法入门(画图模拟:POJ 2083)

    题意:大致就是要求画出这个有规律的Fractal图形了= = 例如 1 对应 X 2 对应 X  X   X    X  X 这个题是个理解分治法很典型的例子(详情请参见Code) 分治法:不断缩小规 ...

  9. poj 1816 (Trie + dfs)

    题目链接:http://poj.org/problem?id=1816 思路:建好一颗Trie树,由于给定的模式串可能会重复,在原来定义的结构体中需要增加一个vector用来记录那些以该节点为结尾的字 ...

  10. POJ 1564 经典dfs

    1.POJ 1564 Sum It Up 2.总结: 题意:在n个数里输出所有相加为t的情况. #include<iostream> #include<cstring> #in ...

随机推荐

  1. Windows下面使用curl

    Windows下面使用curl 学习了:https://www.cnblogs.com/xing901022/p/4652624.html 下载地址:https://curl.haxx.se/down ...

  2. EMERGENCY! EUREKA MAY BE INCORRECTLY CLAIMING INSTANCES ARE UP WHEN THEY'RE NOT. RENEWALS ARE LESSER

    EMERGENCY! EUREKA MAY BE INCORRECTLY CLAIMING INSTANCES ARE UP WHEN THEY'RE NOT. RENEWALS ARE LESSER ...

  3. Linux多线程实践(四 )线程的特定数据

    在单线程程序中.我们常常要用到"全局变量"以实现多个函数间共享数据, 然而在多线程环境下.因为数据空间是共享的.因此全局变量也为全部线程所共同拥有.但有时应用程序设计中有必要提供线 ...

  4. 简单来说一下java中的泛型,ssh中dao层使用会简化代码量

    原来仅仅是听老师说泛型特别好用,但是后来一直弄android用的泛型就比較少了.但是感觉它真的非常重要,于是花了一下午的时间写了个demo.好,老规矩.上代码: 首先,sysout是个工具,可是用着不 ...

  5. cocos2d-x 中XML解析与数据存储

    一不小心就玩了一周的游戏了.哎.玩的时候时间过得总是这么快... 于是今天决定看一下之前不怎么非常熟悉的XML;(之前做游戏时数据的储存用到过XML,但这块是还有一个同事在做,所以不怎么熟悉), 看了 ...

  6. linux内核模块笔记

    主题: 1. 嵌入式基础知识 2. linux内核介绍 3. 内核的编译和安装(x86) 4. 第一个模块 5. 模块的相关工具 6. 模块的符号导出 7. 模块的參数 1.看linux/module ...

  7. emitter 增强 多条件触发

    ;(function(global ,undefined){ var evts = {} ,onceTag = '__event_once' function emit(event ){ ) if ( ...

  8. 棋盘覆盖问题python3实现

    在2^k*2^k个方格组成的棋盘中,有一个方格被占用,用下图的4种L型骨牌覆盖全部棋盘上的其余全部方格,不能重叠. 代码例如以下: def chess(tr,tc,pr,pc,size): globa ...

  9. FPGA中亚稳态——让你无处可逃

    1. 应用背景 1.1         亚稳态发生原因 在FPGA系统中,如果数据传输中不满足触发器的Tsu和Th不满足,或者复位过程中复位信号的释放相对于有效时钟沿的恢复时间(recovery ti ...

  10. MetaSploit攻击实例讲解------社会工程学set攻击(kali linux 2016.2(rolling))(详细)

    不多说,直接上干货! 首先,如果你是用的BT5,则set的配置文件是在 /pentest/exploits/set/set_config下. APACHE_SERVER=ONSELF_SIGNED_A ...