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. nginx禁止未绑定域名访问 并且强行断开连接

    总有些人,会把自己的域名绑到你的主机上. 出于什么原因,我没想到,但你肯定不愿意别人这么做. 在nginx中,用以下代码,配置一个默认主机. server { listen 80 default_se ...

  2. VMware Workstation pro 12下载以及序列号

    VMware Workstation 12序列号:下载地址:https://download3.vmware.com/software/wkst/file/VMware-workstation-ful ...

  3. 【jmeter】浅说 think time

    接口每天被5000个人调用,同时在线500人,每天要被调用50000次.  过了没多久测试完成写了一份报告发给项目经理: 并发 | 响应时间 | 应用服务器cpu |数据库服务器cpu |TPS | ...

  4. 【jmter】JDBC进行mysql数据库测试

    1.添加线程组 2.添加需要的驱动jar包 使用不同的数据库,我们需要引入不同的jar包. 方式1:直接将jar包复制到jmeter的lib目录 mysql数据库:无需引入其他数据库驱动jar包. s ...

  5. LintCode "Backpack"

    A simple variation to 0-1 Knapsack. class Solution { public: /** * @param m: An integer m denotes th ...

  6. 打开SDK Manager检查Android SDK下载和更新失败的解决方法

    [故障描述] 打开SDK Manager检查Android  SDK状况,出现以下情况: Failed to fetch URL https://dl-ssl.google.com/android/r ...

  7. Ajax方法执行跳转或者加载操作系统报出这样错误Sys.WebForms.PageRequestManagerParserErrorException:如何让解决

    当你在代码中使用Response.Redirect();  或者Response.Write();难免会遇到Sys.WebForms.PageRequestManagerParserErrorExce ...

  8. JavaScript-CheckBox全选/反选

    //------------------------------------ // 全/反选 // param checkName checkbox的name属性 //---------------- ...

  9. 黄聪:wordpress如何开启文章格式post format

    发现很多“古老”的WordPress主题使用量非常大,虽然部分也在随着WordPress版本的升级而“升级”,只不过是修复了bug而已,wordpress的新特性并没有使用.而且多数国内的wordpr ...

  10. Spark RDD简介与运行机制概述

    RDD工作原理: 主要分为三部分:创建RDD对象,DAG调度器创建执行计划,Task调度器分配任务并调度Worker开始运行. SparkContext(RDD相关操作)→通过(提交作业)→(遍历RD ...