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
-
解析
一道比较简单的分形图,n<=7,则边长最大为739,开一个800*800的数组记录当前是“X”还是“ ”,当他处于第n级时,如果需要向n-1级递归,就有五个方向:
左上角,右上角,中间,左下角,右下角。
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
int n;
bool maps[][];
inline void dfs(int m,int bian,int xx,int yy)
{
if(m==){
maps[xx][yy]=;
return;
}
dfs(m-,bian/,xx-bian/,yy-bian/);
dfs(m-,bian/,xx-bian/,yy+bian/);
dfs(m-,bian/,xx+bian/,yy-bian/);
dfs(m-,bian/,xx+bian/,yy+bian/);
dfs(m-,bian/,xx,yy);
}
int main()
{
while()
{
memset(maps,,sizeof maps);
scanf("%d",&n);
if(n==-)break;
int bian=;
for(int i=;i<=n-;i++) bian*=;
dfs(n,bian,(bian+)/,(bian+)/);//分别传入第n级,边长(长 和 高相等),中心位置的横纵坐标
for(register int i=;i<=bian;i++)
{
for(register int j=;j<=bian;j++)
{
if(maps[i][j])printf("X");
else printf(" ");
}
printf("\n");
}
printf("-\n");
}
}

 

[POJ2083] Fracal的更多相关文章

  1. poj2083 Fractal

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

  2. poj2083 分形(图形的递归)

    题目传送门 代码有注释. #include<iostream> #include<algorithm> #include<cstdlib> #include< ...

  3. POJ-2083 Fractal-X星阵图

    Description A fractal is an object or quantity that displays self-similarity, in a somewhat technica ...

  4. $Poj2083/AcWing118\ Fractal$ 模拟

    $AcWing$ $Sol$ 一年前做过差不多的南蛮图腾,当时做出来还是很有成就感的$OvO$ $N<=7$,就是模拟模拟,预处理一下,$over$ $Code$ #include<bit ...

  5. Servlet3.0学习总结(二)——使用注解标注过滤器(Filter)

    Servlet3.0提供@WebFilter注解将一个实现了javax.servlet.Filter接口的类定义为过滤器,这样我们在web应用中使用过滤器时,也不再需要在web.xml文件中配置过滤器 ...

  6. A过的题目

    1.TreeMap和TreeSet类:A - Language of FatMouse ZOJ1109B - For Fans of Statistics URAL 1613 C - Hardwood ...

  7. MySQL 高性能存储引擎:TokuDB初探

    在安装MariaDB的时候了解到代替InnoDB的TokuDB,看简介非常的棒,这里对ToduDB做一个初步的整理,使用后再做更多的分享. 什么是TokuDB? 在MySQL最流行的支持全事务的引擎为 ...

  8. MySQL-TokuDB:MySQL 高性能存储引擎:TokuDB

    ylbtech-MySQL-TokuDB:MySQL 高性能存储引擎:TokuDB 1.返回顶部 1. 在安装MariaDB的时候了解到代替InnoDB的TokuDB,看简介非常的棒,这里对ToduD ...

随机推荐

  1. 【转载,备忘】SQL Server 更改跟踪(Chang Tracking)监控表数据

    一.本文所涉及的内容(Contents) 本文所涉及的内容(Contents) 背景(Contexts) 主要区别与对比(Compare) 实现监控表数据步骤(Process) 参考文献(Refere ...

  2. django使用https

    根据以下内容总结了下: http://www.voidcn.com/article/p-xxdfvetx-da.html http://www.voidcn.com/article/p-ezmbnny ...

  3. Delphi快递鸟【支持快递查询和单号识别】

    作者QQ:(648437169) 点击下载➨Delphi快递鸟 [delphi快递鸟]支持快递查询.单号识别.

  4. 安装nginx1.16.1版本

    安装nginx1.16.1版本 一.添加源 到 cd /etc/yum.repos.d/ 目录下 新建nginx.repo 文件 vim nginx.repo 输入以下信息 [nginx-stable ...

  5. python递归函数和河内塔问题

    关于递归函数: 函数内部调用自身的函数. 以n阶乘为例: f(n) = n ! = 1 x 2 x 3 x 4 x...x(n-1)x(n) = n x (n-1) ! def factorial(n ...

  6. Python与MogoDB交互

    睡了大半天,终于有时间整理下拖欠的MongoDB的封装啦. 首先我们先进行下数据库的连接: conn = MongoClient('localhost',27017) # 建立连接 result = ...

  7. Unity - LayerMask简析

    本文简述了LayerMask的定义,后通过项目实战充分解析 LayerMask中的GetMask.LayerToName.NameToLayer 等函数的使用方法及其注意事项. 项目地址:3D坦克大战 ...

  8. Oracle数据库 常用的触发器命令

    创建自增序列,创建触发器(在触发时间中操纵序列,实现主键自增): Oracle数据库不支持自增方法 create sequence seq_userInfo_usid start with ;--创建 ...

  9. Java自学-数组 增强型for循环

    Java 中如何使用增强for循环 增强型for循环在遍历一个数组的时候会更加快捷 步骤 1 : 增强型for循环 注:增强型for循环只能用来取值,却不能用来修改数组里的值 public class ...

  10. 五 查询数据SELECT   一、单表查询

    一 单表查询的语法 二 关键字的执行优先级 三 简单查询 四 WHERE约束 五 分组查询:GROUP BY 六 HAVING过滤 七 查询排序:ORDER BY 八 限制查询的记录数:LIMIT 九 ...