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. vim Google style format

    https://github.com/google/vim-codefmt https://github.com/rhysd/vim-clang-format http://pre.tir.tw/00 ...

  2. redis 的消息订阅和消息队列的功能比较

    消息队列常用的有 rabitMQ.kafka等.缓存服务器  redis 也可以做消息队列使用,他们的特点对比如下 消息协议: 消息队列支持包括AMQP,MQTT,Stomp等,并且支持 JMS 规范 ...

  3. JEECG中表单提交的中断

    JEECG平台中基于form表单封装了<t:formvalid>标签,对应实现的类为FormValidationTag.java文件. 很多时候在正式向后台提交数据前想要做判断处理,若通过 ...

  4. [svc]openssl对称非对称加密实战

    OpenSSL进行aes加密解密-对称加密(symmetry) 建立文件test.txt, 特意写入中英文 # cd /tmp # echo "test测试" > test. ...

  5. leetcode笔记:3Sum Closest

    一.题目描写叙述 二.解题技巧 该题与3Sum的要求类似.不同的是要求选出的组合的和与目标值target最接近而不一定相等.但实际上,与3Sum的算法流程思路类似,先是进行排序.然后顺序选择数组A中的 ...

  6. vue中单选框,利用不存在的值标示选中状态

    1.效果预览 2.index.html <!DOCTYPE html> <html lang="en"> <head> <meta cha ...

  7. (转)解决类似 /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.21' not found 的问题

    转自:https://itbilu.com/linux/management/NymXRUieg.html 源码编译升级安装了gcc后,编译程序或运行其它程序时,有时会出现类似/usr/lib64/l ...

  8. 施工测量中Cad一些非常有用的插件

    经常会遇到坐标在cad中批量展点.从cad中批量保存坐标点.导入cad中的坐标怎么才能有点号,怎么快速标注cad里的坐标点··· ··· 这一切都是可以程序化的,cad是可以二次开发的,我经常用易语言 ...

  9. 在win10企业版x64下使用curl命令

    一.curl命令介绍 curl是利用URL语法在命令行方式下工作的开源文件传输工具.它被广泛应用在Unix.多种Linux发行版中,并且有DOS和Win32.Win64下的移植版本. 详情查看百度百科 ...

  10. CMS 01

    环境搭建 工具 sublime mysql 5.7, 数据库管理 Navicat django 1.10, django shell (可以用来检查错误) 操作系统, windows 7 搭建 dja ...