- 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: ...
随机推荐
- Python:提取网页中的电子邮箱
import requests, re #regex = r"([a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+)"#这个正则表达式过滤 ...
- web打印控件Lodop轻松输出清晰的图表和条码
一.仅用两行语句实现极其复杂的图表打印.类似如下两句: LODOP.ADD_PRINT_CHART(0,0,400,400,5,document.getElementByI d('table001') ...
- SSL介绍(Secure socket Layer & Security Socket Layer)
一个应用程序的安全需求在很大程度上依赖于将如何使用该应用程序和该应用程序将要保护什么.不过,用现有技术实现强大的. 一般用途的安全通常是可能的.认证就是一个很好的示例. 当顾客想从 Web 站点购买某 ...
- iOS开发之Xcode9报错 Compiling IB documents for earlier than iOS7 is no longer supported.
升级到Xcode9时,最低的编译版本为iOS8,但是在使用一些SDK的时候就会报出Compiling IB documents for earlier than iOS7 is no longer s ...
- oracle本地编译问题
oracle10.2: --将过程重新编译为本地编译方式,提示有编译错误,经查提示未设置plsql_native_library_dir 参数 SQL> alter procedure p_xx ...
- ORA-214 signalled during: ALTER DATABASE MOUNT 问题
数据库服务器移动了位置,后来再连其数据库发现提示无法连接,大致为“无法为所有新实例创建连接...”,查看alert日志发现有如下错误: starting up 1 dispatcher(s) for ...
- Hive SQL grouping sets 用法
概述 GROUPING SETS,GROUPING__ID,CUBE,ROLLUP 这几个分析函数通常用于OLAP中,不能累加,而且需要根据不同维度上钻和下钻的指标统计,比如,分小时.天.月的UV数. ...
- docker镜像、容器以及命令操作
docker image docker image是一个极度精简版的Linux程序运行环境,官网的java镜像包括的东西更少,除非是镜像叠加方式的如centos+java7 docker image是 ...
- 2.5 Apache Axis2 快速学习手册之JiBx 构建Web Service
5. 使用JiBX生成服务(通过JIBX 命令将wsdl 生成 services ) 要使用JiBX数据绑定生成和部署服务,请执行以下步骤. 通过在Axis2_HOME / samples / qui ...
- Atitit phpstorm配置attilax总结
Atitit phpstorm配置attilax总结 1. 前期准备 1 1.1. 配置interpreter 1 1.2. debug需要xdebug的支持,不管是script模式还是web模式 3 ...