- Fractal(3.4.1)
Time Limit:1000MS Memory Limit:30000KB 64bit IO Format:%I64d
& %I64u
Description
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
Output
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)的更多相关文章
- Mysql存储引擎之TokuDB以及它的数据结构Fractal tree(分形树)
在目前的Mysql数据库中,使用最广泛的是innodb存储引擎.innodb确实是个很不错的存储引擎,就连高性能Mysql里都说了,如果不是有什么很特别的要求,innodb就是最好的选择.当然,这偏文 ...
- POJ 2083 Fractal
Fractal Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 6646 Accepted: 3297 Descripti ...
- POJ1941 The Sierpinski Fractal
Description Consider a regular triangular area, divide it into four equal triangles of half height a ...
- 分形树Fractal tree介绍——具体如何结合TokuDB还没有太懂,先记住其和LSM都是一样的适合写密集
在目前的Mysql数据库中,使用最广泛的是innodb存储引擎.innodb确实是个很不错的存储引擎,就连高性能Mysql里都说了,如果不是有什么很特别的要求,innodb就是最好的选择.当然,这偏文 ...
- C - Fractal(3.4.1)
Description A fractal is an object or quantity that displays self-similarity, in a somewhat technica ...
- 2015北京网络赛 H题 Fractal 找规律
Fractal Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://hihocoder.com/contest/acmicpc2015beijingo ...
- Fractal(递归,好题)
Fractal Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 8341 Accepted: 3965 Descripti ...
- Codeforces 36B - Fractal
36B - Fractal 思路:分形 代码: #include<bits/stdc++.h> using namespace std; #define ll long long #def ...
- ( 递归 )Fractal -- POJ -- 2083
http://poj.org/problem?id=2083 Fractal Time Limit: 1000MS Memory Limit: 30000K Total Submissions: ...
随机推荐
- ubuntu16 64位 编译64位程序和32位程序
安装了ubuntu16 64位的系统,想在该环境下用gcc编译64位和32位的程序 默认已经安装了64位环境的gcc 1. 首先确认安装的环境是不是64位的 cocoa@cocoaUKlyn:~/De ...
- sublime text修改package安装路径
删除C:\Users\Administrator\AppData\Roaming\Sublime Text 3下面的packages目录 在\Sublime Text 3安装路径下新建Data文件夹 ...
- Spark机器学习(2):逻辑回归算法
逻辑回归本质上也是一种线性回归,和普通线性回归不同的是,普通线性回归特征到结果输出的是连续值,而逻辑回归增加了一个函数g(z),能够把连续值映射到0或者1. MLLib的逻辑回归类有两个:Logist ...
- 【Java】MyBatis与Spring框架整合(二)
本文讲解 Spring 注入映射器及事务功能的实现. 注入映射器实现 MyBatis 可以使用 SqlSession 的 getMapper ( Class<T> type ) 方法,根据 ...
- SSL证书问题汇总
//SLL协议分析 注意:对SSL协议的功能 https://www.myssl.cn/tools/check-server-cert.html //SSL证书格式转换 https://www.it ...
- 基于CentOS搭建Nginx 静态网站
系统要求: CentOS 7.2 64 位操作系统 一. 安装 Nginx(在 CentOS 上,可直接使用 yum 来安装 Nginx) yum install nginx -y 安装完成后,使用 ...
- 【java】解析java网络
目录结构: contents structure [+] 模拟Post与Get请求 设置Authorization头信息 基于TCP的网络编程 TCP协议简介 半关闭的Socket TCP长链接 TC ...
- ListView中的Item点击事件和子控件的冲突或者item点击没有反应的解决的方法
fragment中加入了button和checkbox这些控件.此时这些子控件会将焦点获取到.所以经常当点击item时变化的是子控件.item本身的点击没有响应. 这时候就能够使用descendant ...
- 浅谈MySQL备份字符集的问题
1 引子 MySQL备份时选择字符集是一个难题,特别是字符集不定的业务.mysqldump默认使用utf8,而官方也推荐使用utf8.但实际上,对于中文,部分相当一部分gbk编码字符没有对应的unic ...
- 3.翻译系列:EF Code-First 示例(EF 6 Code-First系列)
原文链接:http://www.entityframeworktutorial.net/code-first/simple-code-first-example.aspx EF 6 Code-Firs ...