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. maven NoClassDefFoundError: org/mortbay/util/Attributes

    在运行mvn jetty:run报错: NoClassDefFoundError: org/mortbay/util/Attributes 解决方法: deleted /home/jenkins/.m ...

  2. 目录处理工具类 DealWithDir.java

    package com.util; import java.io.File; /** * 目录处理工具类 * */ public class DealWithDir { /** * 新建目录 */ p ...

  3. 为什么匿名内部类只能访问其所在方法中的final类型的局部变量?

    大部分时候,类被定义成一个独立的程序单元.在某些情况下,也会把一个类放在另一个类的内部定义,这个定义在其他类内部的类就被称为内部类,包含内部类的类也被称为外部类. class Outer { priv ...

  4. SQL SERVER 生成MYSQL建表脚本

    /****** Object: StoredProcedure [dbo].[GET_TableScript_MYSQL] Script Date: 06/15/2012 13:05:14 ***** ...

  5. 开始学习IOS

    最好的学习方式就是动手. 对于有编程经验的程序员来说,学习另外一门技术最好的方式就是coding,虽然基础知识和IDE都不熟悉,但是在写代码的过程中,不断的解决问题,不断查找资料,不断感悟代码,一切都 ...

  6. WPF--Calendar控件高级使用

    一.得到当前显示的月份: DateTime SelectedDay = this.MC.DisplayDate; 二.得到当前选中的天,得到当前选中的周,得到当前显示的月份: 如果你使用系统默认的事件 ...

  7. LintCode "Continuous Subarray Sum"

    A variation to a classical DP: LCS. class Solution { public: /** * @param A an integer array * @retu ...

  8. C语言每日一题之No.1

    鉴于在学校弱弱的接触过C,基本上很少编程,C语言基础太薄弱.刚好目前从事的是软件编程,难度可想而知.严重影响工作效率,已无法再拖下去了.为此,痛下决心恶补C语言.此前只停留在看书,光看好像也记不住,C ...

  9. 黄聪:wordpress如何获取当前页面的URL

    一行代码搞定 <? echo home_url( add_query_arg( array() ) ); ?>

  10. PLSQL_Oracle临时表Temporary Table基本概念和用法(概念)

    2014-06-08 Created By BaoXinjian