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. 自定义标签tld的使用

    在JSP中使用标签是很平常的事情,在制作自定义标签时,通常都需要写tld文件来定义标签的各种属性,对应的Java类,前缀等等.标签与tld文件紧紧相连,那么,到底应该怎么放置tld文件?在web.xm ...

  2. Java基础之—反射

    反射是框架设计的灵魂 (使用的前提条件:必须先得到代表的字节码的Class,Class类用于表示.class文件(字节码))   一.反射的概述 JAVA反射机制是在运行状态中,对于任意一个类,都能够 ...

  3. HTML JavaScript语法练习

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  4. Java.Annotations

    Annotation 0. Annotation Tricks http://developer.android.com/reference/java/lang/annotation/Annotati ...

  5. BZOJ1935或洛谷2163 [SHOI2007]园丁的烦恼

    BZOJ原题链接 洛谷原题链接 很容易想到二维前缀和. 设\(S[i][j]\)表示矩阵\((0, 0)(i, j)\)内树木的棵数,则询问的矩形为\((x, y)(xx, yy)\)时,答案为\(S ...

  6. UIButton 设置图片文字垂直居中排列

    #pragma mark 按钮图片文字垂直居中排列 -(void)setButtonContentCenter:(UIButton *)button { CGSize imgViewSize,titl ...

  7. libpcap 库使用(二)

    参考资料: http://www.tcpdump.org/manpages/pcap.3pcap.html 分类介绍了该lib的函数 Opening a capture handle for read ...

  8. Spring 注解原理(一)组件注册

    Spring 注解原理(一)组件注册 Spring 系列目录(https://www.cnblogs.com/binarylei/p/10198698.html) 当我们需要使用 Spring 提供的 ...

  9. 论坛:排序 >>case..when..then ..end的妙用

    a.主题列表按 最后更新时间 进行排序 数据库SQL语句中没有if..else的判断语句,但是oracle中有decode()函数可以实现这种判断语句,但是还可以用case..when..then . ...

  10. jQuery加载完成事件 $(function(){ })的全局异常拦截

    通常我们在页面加载完成的时候要写入一些功能脚本,如: $(function(){/*脚本 - 1*/ console.log('start'); }) $(function(){/*脚本 - 2*/ ...