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

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 <math.h>
#include <iostream>
using namespace std; char Map[][]; void DFS(int n, int x, int y)
{
if (n == )
{
Map[x][y] = 'X';
return;
}
int size = pow(3.0, n - );
DFS(n - , x, y);// 左上角
DFS(n - , x, y + size * );//右上角
DFS(n - , x + size, y + size);//中间
DFS(n - , x + size * , y);//左下角
DFS(n - , x + size * , y + size * );//右下角
} int main()
{
int n, size;
while(scanf("%d", &n) != NULL && n != -)
{
size = pow(3.0, n - );
for (int i = ; i <= size; i++)
{
for (int j = ; j <= size; j++)
{
Map[i][j] = ' ';
}
Map[i][size + ] = '\0';
}
DFS(n, , );
for (int i = ; i <= size; i++)
{
printf("%s\n", Map[i] + );
}
printf("-\n");
}
return ;
}

POJ 2083 Fractal的更多相关文章

  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 分形

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

  4. ( 递归 )Fractal -- POJ -- 2083

    http://poj.org/problem?id=2083 Fractal Time Limit: 1000MS   Memory Limit: 30000K Total Submissions:  ...

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

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

  6. POJ 3845 Fractal(计算几何の旋转缩放)

    Description Fractals are really cool mathematical objects. They have a lot of interesting properties ...

  7. POJ 3889 Fractal Streets(逼近模拟)

    $ POJ~3889~Fractal~Streets $(模拟) $ solution: $ 这是一道淳朴的模拟题,最近发现这种题目总是可以用逼近法,就再来练练手吧. 首先对于每个编号我们可以用逼近法 ...

  8. poj2083 Fractal

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

  9. dir命令只显示文件名

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

随机推荐

  1. 通过JavaScript脚本实现验证码自动输入

    很多网站在用户进行某次点击,比如在线购物确认购买时,会要求用户输入验证码,这在一般情况下也没啥问题,但在用户需要频繁购买或是抢购时就很讨厌了.其实网站的验证码一般是由JS脚本生成的,因此也可以通过编写 ...

  2. 使用jQuery和CSS3生成的搜索框变形全屏搜索效果

    在线演示 本地下载 使用jQuery和CSS3过渡变形效果生成的一个搜索框变形效果实现,可以帮助你更好利用页面格式和内容.实验性质的代码,请大家在产品环境里自己修改使用!

  3. paip.关于动画特效原理 html js 框架总结

    paip.关于动画特效原理 html js 框架总结 1. 动画框架的来源:flex,jqueryui 3 2. 特效的分类 3 2.1. Property effects 动态改变一个或多个目标对象 ...

  4. Javascript正则表达式的初步学习

    <html> <head> <meta charset="utf-8"> <title>正则表达式的学习</title> ...

  5. 如何安装、配置Apache

    Apache的安装流程网上版本很多,但很多版本有错误,或者缺漏,如果初学者按照那样安装的话会遇到各种各样的问题.我整理了自己安装.配置Apache的过程,亲测有效,分享给大家. 基本过程如下: Dow ...

  6. css解决谷歌,360浏览器默认最小字体为12px问题

    当我们设置前台html页面样式问题字体小于12px;时,会发现不管怎么设置小于12px字体,在谷歌.360浏览器上都不生效. 但在火狐等浏览器上却可以正常设置,当你打开谷歌360的设置后会发现,它们设 ...

  7. Windows 8.1 with update 官方最新镜像汇总

    Windows 8.1 with update 官方最新镜像汇总,发布日期: 2014/12/16,Microsoft MSDN. 镜像更新日志: 12/29:32位大客户专业版中文版 12/24:6 ...

  8. (转)【Unity3d】Glow + Outline 轮廓描边

    转:http://www.cnblogs.com/dosomething/archive/2012/08/04/2622488.html [Unity3d]Glow + Outline 轮廓描边 轮廓 ...

  9. HBase + Kerberos 配置示例(一)

    用过hbase的朋友可能都有过这样的疑问,我写一个java client,好像就提供了zookeeper quorum地址就连上hbase了,那么是不是存在安全问题?的确是,如何解决?hbase中引入 ...

  10. [译]PostCSS介绍

    PostCSS介绍 原文链接:http://www.smashingmagazine.com/2015/12/introduction-to-postcss/ 转自:http://www.zcfy.c ...