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. MySQL group_concat 1024 大小

    1. GROUP_CONCAT有个最大长度的限制,超过最大长度就会被截断掉,你可以通过下面的语句获得: SELECT @@global.group_concat_max_len; show varia ...

  2. windows下安装mysql压缩包版[转]

    版本:5.6.17 1.将解压后的文件夹放到某个目录下,比如c:\software; 2.在环境变量中新建MYSQL_HOME=C:\software\mysql-5.6.17-winx64,然后在系 ...

  3. JavaScript-分支语句与函数

    一.分支语句-if语句 四种if语句: 1.if(判断条件) { 满足条件时需执行的语句 } 2.if(判断条件) { 满足条件时需执行的语句 } else { 不满足条件时需执行的语句 } 3.if ...

  4. java生成竖排文字图片

    package com.kadang.designer.web.action;import java.awt.Color;import java.awt.Font;import java.awt.Fo ...

  5. dom4j 读取xml

    package core.util; import java.io.File; import java.util.Iterator; import java.util.List; import org ...

  6. nodejs gearman redis

    export NODE_PATH=/root/gearman-1.1.2/node_modulesnpm install gearmanodenpm install redis w.js var re ...

  7. 于网站主机,DNS,域名解析,Web服务器关系详解

    /*本文将介绍网站主机,DNS,域名解析,Web服务器关系,转载请保留以下版权*/ /*启明星工作室 www.dotnetcms.org  提供会议室预定系统,请假系统,helpdesk,工作日志系统 ...

  8. GO語言基礎教程:Hello world!

    首先簡單地說一下GO語言的環境安裝,從 http://golang.org/dl/ 針對自己的操作系統選擇合適的安裝包,然後下載安裝即可,下載的時候注意別選錯了的操作系統,例如go1.3.1.darw ...

  9. Node.js的颠覆者:PHP的Swoole扩展

          最近2年Node.js很火,异步与协程是网络开发方面热门的话题.在追求新技术的同时,也应该反思下这里面存在的陷阱.Node.js确实是一门有趣好玩有个性的语言和技术,动态性,全异步回调的方 ...

  10. 转:RTMPDump源代码分析

    0: 主要函数调用分析 rtmpdump 是一个用来处理 RTMP 流媒体的开源工具包,支持 rtmp://, rtmpt://, rtmpe://, rtmpte://, and rtmps://. ...