http://poj.org/problem?id=2083

Fractal
Time Limit: 1000MS   Memory Limit: 30000K
Total Submissions: 8317   Accepted: 3957

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
  • 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

递归这个神奇的东西, 然而我并没有会, 唉, 感觉就只是懂了皮毛, 稍微加点难度的就不会, 真失败, 以后好好用用

#include<stdio.h>
#include<string.h> #define N 1100 int a[20];
bool G[N][N]; void DFS(int n, int x, int y)
{
G[x][y] = true; if(n==7)
return ; int s = a[n]; DFS(n+1, x, y);
DFS(n+1, x, y+s*2 );
DFS(n+1, x+s, y+s);
DFS(n+1, x+s*2, y);
DFS(n+1, x+s*2, y+s*2);
} int main()
{
int i, j, n; memset(G, false, sizeof(G)); a[1] = 1;
for(i=2; i<=10; i++)
a[i] = a[i-1]*3; DFS(1, 1, 1); while(scanf("%d", &n), n!=-1)
{ for(i=1; i<=a[n]; i++)
{
for(j=1; j<=a[n]; j++)
{
if(G[i][j]==true)
printf("X");
else
printf(" ");
}
printf("\n");
} printf("-\n");
}
return 0;
}

 

下面粘个错误代码, 自己刚开始写的, 仔细看看是我没有很好的注意分层的问题, 在每一层递归的时候,应该记录一下它有用的信息, 然而我并没有。这题, 错就错在没有很好的注意分层的问题

#include<stdio.h>
#include<string.h> int n, G[N][N]; void DFS(int x, int y)
{
G[x][y] = ; if(x== && y==)
{
G[x][y] = ;
return ;
} DFS(x, y+);
DFS(x+, y+);
DFS(x+, y);
DFS(x+, y+);
} int main()
{
int n, a[]={,}; memset(G, , sizeof(G)); for(i=; i<=; i++)
a[i] = a[i-]*; DFS(, ); while(scanf("%d", &n), n!=-)
{ int i, j; for(i=; i<=a[n]; i++)
{
for(j=; j<=a[n]; j++)
{
if(G[i][j]==)
printf("X");
else
printf(" ");
}
printf("\n");
} printf("-\n");
}
return ;
}

( 递归 )Fractal -- POJ -- 2083的更多相关文章

  1. poj 2083 Fractal 递归 图形打印

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

  2. POJ 2083 Fractal 分形题目

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

  3. POJ 2083 Fractal

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

  4. POJ 2083 Fractal 分形

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

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

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

  6. poj2083 Fractal

    我一开始的想法是间断性的输出空格和solve(k-1) 但是发现问题很大. 雨菲:可以用一个数组保存啊 我:那不爆了? 雨菲:不会爆. 我一算:729 × 729,还真没爆. 然后就直接WA了.... ...

  7. dir命令只显示文件名

    dir /b 就是ls -f的效果 1057 -- FILE MAPPING_web_archive.7z 2007 多校模拟 - Google Search_web_archive.7z 2083 ...

  8. A过的题目

    1.TreeMap和TreeSet类:A - Language of FatMouse ZOJ1109B - For Fans of Statistics URAL 1613 C - Hardwood ...

  9. $2019$ 暑期刷题记录1:(算法竞赛DP练习)

    $ 2019 $ 暑期刷题记录: $ POJ~1952~~BUY~LOW, BUY~LOWER: $ (复杂度优化) 题目大意:统计可重序列中最长上升子序列的方案数. 题目很直接的说明了所求为 $ L ...

随机推荐

  1. NC 日志文件注册

    在实际开发中,例如接口向外系统发送数据,这些数据前台看不到,一般都是记录日志,然后在后台日志文件中查看.但是,用系统原本日志文件来看,有时会记录一些别的模块日志信息.所以,我们可以注册个自己的模块日志 ...

  2. java 环境搭建

    一.安装jdk 下载jdk http://www.oracle.com/technetwork/java/javase/downloads 将下载的jdk文件放到 /opt 下解压 $sudo cp ...

  3. [SoapUI] 从Map里面不想要的键值对

    def keysToRemoveForBoss = ["RequestIdBmk", "RequestIdTest"] def extraInfoMapForB ...

  4. Spring ApplicationContext(六)BeanPostProcessor

    Spring ApplicationContext(六)BeanPostProcessor 产生回顾一下 ApplicationContext 初始化的几个步骤:第一步是刷新环境变量:第二步是刷新 b ...

  5. Ubutun 配置php redis 扩展

    1.安装redis 下载:wget --no-check-certificate https://github.com/nicolasff/phpredis/archive/2.2.4.tar.gz ...

  6. autohotkey快捷键

    ;已经基本修复了输入带shift的时候跟输入法中英文切换之间的冲突 SetStoreCapslockMode, off SetKeyDelay, ^CapsLock:: #UseHook ;用这个和下 ...

  7. java调用第三方包的例子

    第三方包路径 D:\jp\log4j\log4j-1.2.16.jar 代码D:\jp\log4j\Log4jDemo.java import org.apache.log4j.*; public c ...

  8. 清华大学 TUNA 协会

    https://tuna.moe/ 技术,实力,优越感,环境..,镜像

  9. Windows AD域管理软件

  10. mysql 字符串数值计算 精度丢失

    我进行了一些测试.truncate(abs('414')/100,2)truncate('414'/100,2)truncate('4.14',2)truncate('4.1400',2)都有精度丢失 ...