C - Fractal(3.4.1)

Time Limit:1000MS    Memory Limit:30000KB    64bit IO Format:%I64d
& %I64u

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
-
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
using namespace std;
#define M 1000
char s[M][M];
void print( int n, int x, int y)
{
int m;//m 表示方盒子规模 即边长
double t=3;
if( n == 1 )
{
s[x][y] = 'X'; //回溯,当n=1时,为(x,y)坐标赋值'X'
return ;
}
else if( n > 1 )
{
m = pow( t, n - 2 ); //计算盒子规模
print( n - 1, x, y ); //左上角第一个图形进行递归打印,第一个图形左上角坐标为(x,y)
print( n - 1, x, y + 2 * m ); //右上角第二个图形进行递归打印,第二个图形左上角坐标为(x,y+2*m)
print( n - 1, x + m, y + m ); //中间第三个图形进行递归打印,第三个图形左上角坐标为(x+m,y+m)
print( n - 1, x + 2 * m, y ); //左下角第四个图形进行递归打印,第四个图形左下角坐标为(x+2*m,y)
print( n - 1, x + 2 * m, y + 2 * m);//右下角第五个图形进行递归打印,第五个图形右下角坐标为(x+2*m,y+2*m)
}
} int main()
{
int n, i, p; double t=3;
while(cin >> n && n != -1 )
{
p = pow( t, n - 1 ); //计算方盒子规模
for( i = 0; i < p; i++ ) //对数组进行初始化
{
memset( s + i, ' ', p ); //每一行均初始化为空格
s[i][p] = '\n'; //每一行最后一列初始化为换行,如果不这样做,会出错,图形无法输出
}
print( n, 0, 0 ); //从左上角(x,y)坐标开始打印
for( i = 0; i < p; i++)
cout << s[i] ; //输出图形
cout << '-' << endl;
}
return 0;
}

- 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. C - Fractal(3.4.1)

    Description A fractal is an object or quantity that displays self-similarity, in a somewhat technica ...

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

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

  7. Fractal(递归,好题)

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

  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. 修改oracle为归档模式

    1.查看是否为归档模式 SQL> archive log list; Database log mode No Archive Mode Automatic archival Disabled ...

  2. 【转】CLR和JIT的理解、.NET反汇编学习

    CLR:通用语言运行时(Common Language Runtime)的简称,CLR是.NET框架的核心内容之一,可以把它看为一套标准资源,可以呗任何.NET程序使用.它包括:面向对象的编程模型.安 ...

  3. JAVA中通过时间格式来生成唯一的文件名

    有时候我们需要截图,在要截图时,有人用到了时间格式,但是时间格式中的:在文件名称中是不被允许的字符,所以就会报错,如何生成唯一的时间文件名: package com.demo; import java ...

  4. spring-mybatis代码生成插件,与实例展示

    前段时间看了张开涛写的代码生成插件,感觉思路很好,通过连接库然后获取数据库表信息,然后用户在界面中勾选要映射的策略,映射的字段,然后可以自动生成业务代码. 基于开涛的思路,自己写了一个简易插件,去掉了 ...

  5. 在Asp.Net MVC中使用Repeater控件

    使用Repeater控件在视图中展示图表信息,Repeater控件的使用概述: <asp:Repeater ID="Repeater1" runat="server ...

  6. C#_基础题1-10套答案

    one 1.用户输入一个整数,用if...else判断是偶数还是奇数             Console.WriteLine("请输入一个整数:");              ...

  7. Spark 核心篇-SparkContext

    本章内容: 1.功能描述 本篇文章就要根据源码分析SparkContext所做的一些事情,用过Spark的开发者都知道SparkContext是编写Spark程序用到的第一个类,足以说明SparkCo ...

  8. 菜鸟学Java(二十三)——Java内存分析

    我们常说的Java内存主要分为四大块(寄存器不在考虑之内,我们无法用代码来操控它):stack(栈).heap(堆).data segment(数据区).code segment(代码区).它们的主要 ...

  9. 为11.2.0.2 Grid Infrastructure添加节点

    转自:http://www.askmaclean.com/archives/add-node-to-11-2-0-2-grid-infrastructure.html 在之前的文章中我介绍了为10g ...

  10. 【Ubuntu】PHP环境安装-phpstudy for linux版

    安装: wget -c http://lamp.phpstudy.net/phpstudy.bin chmod +x phpstudy.bin    #权限设置sudo ./phpstudy.bin ...