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

对这样的递归图形问题,只是简单的将其写出函数即找出规律,然后找出边界,然后写成递归就行了

有点逗比的是将题目中的-写成了_,wr了好多次!!!!

本题使用函数pow(a,b)即a的b次方

#include <iostream>
#include <cstdio>
#include <memory.h>
#include <cmath>
using namespace std;
char map[1000][1000];
void paint(int n,int x,int y){
if(n==1){
map[x][y]='X';
return;
}
int size = (int)pow(3.0,n-2);
paint(n-1, x, y); //左上角
paint(n-1, x, y+size*2); //右上角
paint(n-1, x+size, y+size); //中間
paint(n-1, x+size*2, y); //左下角
paint(n-1, x+size*2, y+size*2); //右下角
}
int main(){
int n;
while (~scanf("%d",&n)&&n!=-1){
int size=(int)pow(3.0, n-1); //度为n的分形图的规模是3^(n-1)
memset(map,' ',sizeof(map));
paint(n, 1, 1);
for (int i=1;i<=size;i++ ) { //列印
for(int j=1;j<=size;j++)
cout<<map[i][j];
cout<<endl;
}
cout<<'-'<<endl;
}
return 0;
}

C - Fractal(3.4.1)的更多相关文章

  1. Mysql存储引擎之TokuDB以及它的数据结构Fractal tree(分形树)

    在目前的Mysql数据库中,使用最广泛的是innodb存储引擎.innodb确实是个很不错的存储引擎,就连高性能Mysql里都说了,如果不是有什么很特别的要求,innodb就是最好的选择.当然,这偏文 ...

  2. POJ 2083 Fractal

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

  3. POJ1941 The Sierpinski Fractal

    Description Consider a regular triangular area, divide it into four equal triangles of half height a ...

  4. 分形树Fractal tree介绍——具体如何结合TokuDB还没有太懂,先记住其和LSM都是一样的适合写密集

    在目前的Mysql数据库中,使用最广泛的是innodb存储引擎.innodb确实是个很不错的存储引擎,就连高性能Mysql里都说了,如果不是有什么很特别的要求,innodb就是最好的选择.当然,这偏文 ...

  5. 2015北京网络赛 H题 Fractal 找规律

    Fractal Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://hihocoder.com/contest/acmicpc2015beijingo ...

  6. Fractal(递归,好题)

    Fractal Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 8341   Accepted: 3965 Descripti ...

  7. - Fractal(3.4.1)

    C - Fractal(3.4.1) Time Limit:1000MS    Memory Limit:30000KB    64bit IO Format:%I64d & %I64u Su ...

  8. Codeforces 36B - Fractal

    36B - Fractal 思路:分形 代码: #include<bits/stdc++.h> using namespace std; #define ll long long #def ...

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

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

随机推荐

  1. WCF学习心得------(二)设计和实现服务协定

    设计和实现服务协定 创建服务协定—WCF术语 消息 消息是一个独立的数据单元,它可能由几个部分组成,包括消息正文和消息头. 服务 服务是一个构造,它公开一个或多个终结点,其中每个终结点都公开一个或多个 ...

  2. C#Random()函数详解

    随机数的使用很普遍,可用它随机显示图片,用它防止无聊的人在论坛灌水还可以用来加密信息等等.本文讨论如何在一段数字区间内随机生成若干个互不相同的随机数,比如在从1到20间随机生成6个互不相同的整数,并通 ...

  3. 【jmeter】测试报告优化<二>

    如果按JMeter默认设置,生成报告如下: 从上图可以看出,结果信息比较简单,对于运行成功的case,还可以将就用着.但对于跑失败的case,就只有一行assert错误信息.(信息量太少了,比较难找到 ...

  4. Neutron分析(3)—— neutron-l3-agent

    一.Layer-3 Networking Extension neutron l3作为一种API扩展,向租户提供了路由和NAT功能. l3扩展包含两种资源: router:在不同内部子网中转发数据包: ...

  5. Python builtins

    >>> dir (__builtins__) ['ArithmeticError', 'AssertionError', 'AttributeError', 'BaseExcepti ...

  6. mysql 常用操作(整理)

    原文地址:http://blog.csdn.net/lxh090821/article/details/9410943 1       登录数据库 格式: mysql -h主机地址 -u用户名 -p用 ...

  7. Java事务处理全解析(一)——Java事务处理的基本问题

    Java中的事务处理有多简单?在使用EJB时,事务在我们几乎察觉不到的情况下发挥着作用:而在使用Spring时,也只需要配置一个TransactionManager,然后在需要事务的方法上加上Tran ...

  8. 解决pdm打开只显示表名不显示字段的步骤

    解决pdm打开只显示表名不显示字段的方法 选中PDM 依次点击 工具-->显示参数选择-->content 下面的table ,右边勾选上columns 点击OK 选择 all symbo ...

  9. PLSQL_性能优化系列01_Oracle Index索引

    2014-06-01 Created By BaoXinjian

  10. MYSQL 安装更新,使用,管理,备份和安全等

    如何安装更新,使用,管理,备份和安全,维护优化一个MYSQL系统. 一.MYSQL发展历史,特点.对SQL语法进行介绍 二.如何安装一个MYSQL系统 三四.如何利用SQL语言以及其他的客户工具对MY ...