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. springMvc入门--初识springMvc

    springMvc是什么 springmvc是表现层的框架,是一个spring的表现层组件.是整个spring框架的一部分,但是也可以不使用springmvc.跟struts2框架功能类似.其中的mv ...

  2. 快速掌握Ajax-Ajax基础实例(Ajax返回Json在Java中的实现)

    (转)实例二:Ajax返回Json在Java中的实现 转自http://www.cnblogs.com/lsnproj/archive/2012/02/09/2341524.html#2995114 ...

  3. hdu 4004 (二分加贪心) 青蛙过河

    题目传送门:http://acm.hdu.edu.cn/showproblem.php?pid=4004 题目意思是青蛙要过河,现在给你河的宽度,河中石头的个数(青蛙要从石头上跳过河,这些石头都是在垂 ...

  4. javascript 高级程序设计 十

    理解JS对象(2)创建对象   JS中创建对象的方式有很多,我们把他们统称为模式. 工厂模式: 优点:解决了创建多个相似对象的问题. 缺点:没有解决对象识别问题.(不知道一个实例对象的类型) func ...

  5. HapMap

    HapMap五周年回顾 2011-01-12 | 作者: [关闭] 作者简介:曾长青,中国科学院北京基因组所研究员,博士生导师.CUSBEA奖学金.百人计划.杰出青年基金.首批新世纪百千万人才工程国家 ...

  6. HDOJ2586 How far away ?

    一道LCA模板 原题链接 \(LCA\)模板题,不解释. 倍增版 #include<cstdio> #include<cmath> #include<cstring> ...

  7. nodejs 如何操作字节在内存中的位置问题 BE LE

    上代码 function testNumber() { var arr = new Int32Array(1); arr[0] = 1234; var buf1 = Buffer.from(arr); ...

  8. ubuntu安装jre

    1)登录java官网,下载jre,并解压,解压后的jre文件夹移动到 /usr/lib/java 路径下 2)配置系统环境变量 JAVA_HOME CLASSPATH PATH 打开/etc/envi ...

  9. How-to Install VMware Tools on Debian Stretch 9 32/64bit Linux+GNU

    在虚拟机VMWARE上安装debian9 安装vmwaretools时候遇到问题 询问我IFCONFIG安装在哪里? 新版的debian不知道是用户权限问题还是使用了其他网络配置工具 vmwareto ...

  10. clean

    启动tomcat 报 Could not delete D:/online/.metadata/.plugins/org.eclipse.wst.server.core/tm