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. 关于SQLServer2005的学习笔记—异常捕获及处理

    转自:http://blog.csdn.net/baoqiangwang/article/details/5395874 SQLServer2005 提供了类似于 C# 和 C++ 语言中的异常处理的 ...

  2. C# 常见集合之前的转换

    1,从System.String[]转到List<System.String> System.String[] str={"str","string" ...

  3. javascript中的removeEventListener失效问题

    一般现在我们用js绑定事件是 addEventListener(event,function,bool) event:事件的名称 字符串 如:'click', function: 事件处理的方法: b ...

  4. Jquery实现购物车物品数量的加减特效

    今天网友翠儿在用Jquery实现购物车物品数量的加减特效的时候遇到问题来问我,我后来帮她解决了这个Jquery特效,现在把它整理出来分享给大家用,虽然功能比较简单,但是很实用. 主要包括了以下功能: ...

  5. $_SERVER 相关变量

    PHP编程中经常需要用到一些服务器的一些资料,特把$_SERVER的详细参数整理下,方便以后使用. $_SERVER['PHP_SELF'] #当前正在执行脚本的文件名,与 document root ...

  6. 微博一键分享主要通过对指定 URL 添加各种参数来实现;

    微博一键分享主要通过对指定 URL 添加各种参数来实现:也可以用在线生成器自动生成. 示例: 搜狐微博一键分享 URL,只需三个参数: http://t.sohu.com/third/post.jsp ...

  7. rabbitmq例子

    安装 sudo apt-get install rabbitmq-server 开启后台管理 sudo rabbitmq-plugins enable rabbitmq_management;sudo ...

  8. AngularJS PhoneCat代码分析

    转载自:http://www.tuicool.com/articles/ym6Jfen AngularJS 官方网站提供了一个用于学习的示例项目:PhoneCat.这是一个Web应用,用户可以浏览一些 ...

  9. 技巧分享——如何去除多余的CSS代码?

    有时候,当你的CSS代码过多的时候,而且已经明确知道有部分CSS代码是多余的: 这时候,有什么较快的办法可以去除多余的CSS呢?? 下面分享一个实用技巧: 1.使用谷歌浏览器:Chrome .下载 2 ...

  10. (VS) TFS lost mapping suddenly.

    家里的网络不是很稳定.今天突然发现 TFS 上所有的 mapping都突然没有了. 尝试去remapping,在Source Control Explorer 中右击源文件,然后选择 Advanced ...