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. echarts 柱状图和饼状图动态获取后台数据

    运用echarts来实现图表 1.首先下载echarts包  http://echarts.baidu.com/echarts2/doc/example.html,在这里我下载的是 2.将echart ...

  2. 使用malloc分别分配2KB的空间,然后用realloc调整为6KB的内存空间,打印指针地址

    #include<stdio.h> #include<stdlib.h> #include<string.h> #include<malloc.h> i ...

  3. bzoj1022: [SHOI2008]小约翰的游戏John(博弈SG-nim游戏)

    1022: [SHOI2008]小约翰的游戏John 题目:传送门 题目大意: 一道反nim游戏,即给出n堆石子,每次可以取完任意一堆或一堆中的若干个(至少取1),最后一个取的LOSE  题解: 一道 ...

  4. WIN7使用VisualSVN建立SVN服务器

    使用SVN开发十分的方便,这样就不用每次都拷贝粘贴来备份了,网上看到一篇给自己的windows电脑安装SVN服务器的使用非常方便. 1.下载安装文件(服务器端和客户端) 服务器端采用VisualSVN ...

  5. Linux下grub的配置文件

    GRUB(统一引导装入器)是基本的Linux引导装入器. 其有四个作用,如下: 1.选择操作系统(如果计算机上安装了多个操作系统). 2.表示相应引导文件所在的分区. 3.找到内核. 4.运行初始内存 ...

  6. BOOL的getter方法

    在代码中经常会看到这样的属性声明 @property (nonatomic,assign,getter = isRead)BOOL read; 这行代码的意思就是,声明一个BOOL类型的read,但是 ...

  7. C# 运算符 ?、??、?: 、?. 、 各种问号的用法和说明

    1. 可空类型修饰符(?):引用类型可以使用空引用表示一个不存在的值,而值类型通常不能表示为空.例如:string str=null; 是正确的,int i=null; 编译器就会报错.为了使值类型也 ...

  8. sqluldr2linux64.bin的使用

    使用sqluldr2linux64.bin的前提是已经安装了Oracle数据库,sqluldr2linux64.bin和Oracle在同一台主机上使用,使用之前需要赋予可执行权限: [root@nod ...

  9. 我的Java历程_spring+springmvc+mybatils整合问题

    作为一个初学框架的菜鸟,有时候遇到异常时真的不好判断问题的出处,因为一般框架不就是导jar包,配置文件嘛,对于一个新手来说要看懂错误出现的含义韩式有些难的,lz昨天整合spring+mybatils时 ...

  10. MyBatis中关于SQL标签的用法(重用SQL 代码段)

    一. 没用sql标签前的SQL映射代码: <select id="findById" resultType="cn.tedu.mybatis.entity.User ...