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. electron+vue实现菜单栏

    公司开发的产品都是用c++写的,而且还都是几个人,老板想搞下创新,就是看看能否通过其它的方式来实现前后端分离.然后我就了解到了electron这个东西,之前学安卓的时候看到过flutter,不经意间看 ...

  2. lua【卤鹅】总结

    转自:https://www.cnblogs.com/reblue520/p/10767428.html 编写一个简单的hello world程序 test.lua 如果觉得简单,可以给一个for循环 ...

  3. Java基础知识点总结(三)

    figure:first-child { margin-top: -20px; } #write ol, #write ul { position: relative; } img { max-wid ...

  4. windows和linux环境下java调用C++代码-JNI技术

    最近部门做安卓移动开发的需要调C++的代码,困难重重,最后任务交给了我,查找相关资料,没有一个教程能把不同环境(windows,linux)下怎么调用说明白的,自己在实现的过程中踩了几个坑,在这里总结 ...

  5. golang微服务框架go-micro 入门笔记2.2 micro工具之微应用利器micro web

    micro web micro 功能非常强大,本文将详细阐述micro web 命令行的功能 阅读本文前你可能需要进行如下知识储备 golang分布式微服务框架go-micro 入门笔记1:搭建go- ...

  6. Mysql的常见索引

    PRIMARY KEY(主键索引) ALTER TABLE table_name ADD PRIMARY KEY ( col ) 它是一种特殊的唯一索引,不允许有空值: UNIQUE(唯一索引) AL ...

  7. python 2种创建多线程的方法

    多个线程是可以操作同一个全局变量的,因此,可以通过这种方式来判断所有线程的执行进度 # 第一种方法:将要执行的方法作为参数传给Thread的构造方法 import threading import t ...

  8. 【题解】Luogu P5324 [BJOI2019]删数

    原题传送门 易知这个数列的顺序是不用考虑的 我们看两个数列 \(1,2,3\)和\(3,3,3\)都能删完,再看两个数列\(1,2,3,4\)和\(2,2,4,4\),也都能删完 不难发现,我们珂以把 ...

  9. MMKV 多进程K-V组件 MD

    Markdown版本笔记 我的GitHub首页 我的博客 我的微信 我的邮箱 MyAndroidBlogs baiqiantao baiqiantao bqt20094 baiqiantao@sina ...

  10. (1)ASP.NET Core 应用启动Startup类简介

    1.前言 Core与早期版本的 ASP.NET 对比,配置应用程序的方式的 Global.asax.FilterConfig.cs和RouteConfig.cs 都被Program.cs 和 Star ...