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. SQL语法的重要知识点总结

    好几年没写SQL语句了.现在到了新的team,需要用到数据库.作为QA的话时常需要使用客户端工具连接到数据库中找寻或修改数据.这么长时间没使用,一些SQL的使用技巧都忘得差不多了.晚上看了一些资料,花 ...

  2. MongoDB与.NET结合使用一(mongodb在windows 2003上的安装)

    mongodb发展至今已经到2.6版本了,自从获得了1亿美元的风投之后,发展速度更是比以前快了很多,前段时间因为要用缓存,也比较了mongodb,大家也都觉得比较适合做无关系化的大数据存储,所以系统统 ...

  3. 阿里云服务器PPTP VPN安装记录

    # sudo apt-get install pptpd   http://blog.kunyu.li/digitalocean-ubuntu-vps-vpn.html     iptables管理 ...

  4. JS 日期格式化和解析工具

    本来想模仿Java里面的SimpleDateFormat()对象的,但是感觉这样用起来不方便,所以还是直接写成单独的方法算了. 原文链接 日期格式化 使用说明 formatDate(date, fmt ...

  5. Java-基础练习2

    1.利用文本编辑器输入课堂上练习的Hello.java,并在JDK环境下编译和运行.请将程序编译.运行的结果截图,填入下框中. class Hello{ public static void main ...

  6. JAVA学习Swing章节按钮组件JButton的简单学习

    package com.swing; import java.awt.Container; import java.awt.Dimension; import java.awt.GridLayout; ...

  7. python函数的参数

    代码: # coding=utf8 # 可以传入任何个参数 def calc(*numbers): sum = 0 for n in numbers: sum = sum + n * n return ...

  8. Leetcode-203 Remove Linked List Elements

    #203.   Remove Linked List Elements Remove all elements from a linked list of integers that have val ...

  9. QQ邮箱的安全问题

    下午同事群里有人提醒,小心欺诈邮件.邮件内容为你的帐户在XX存在异地登录,已经进入了[保护模式],如需解除请点击[解除保护模式] 除了链接之外,其它跟官方的是一模一样,包括标题. 那个链接的地址是:h ...

  10. IOS-TextField控件详解

    //初始化textfield并设置位置及大小 UITextField *text = [[UITextField alloc]initWithFrame:CGRectMake(20, 20, 130, ...