POJ 1941 The Sierpinski Fractal
总时间限制: 1000ms 内存限制: 65536kB
描述
Consider a regular triangular area, divide it into four equal triangles of half height and remove the one in the middle. Apply the same operation recursively to each of the three remaining triangles. If we repeated this procedure infinite times, we'd obtain something with an area of zero. The fractal that evolves this way is called the Sierpinski Triangle. Although its topological dimension is 2, its Hausdorff-Besicovitch dimension is log(3)/log(2)~1.58, a fractional value (that's why it is called a fractal). By the way, the Hausdorff-Besicovitch dimension of the Norwegian coast is approximately 1.52, its topological dimension being 1.
For this problem, you are to outline the Sierpinski Triangle up to a certain recursion depth, using just ASCII characters. Since the drawing resolution is thus fixed, you'll need to grow the picture appropriately. Draw the smallest triangle (that is not divided any further) with two slashes, to backslashes and two underscores like this:
/\
/__\
To see how to draw larger triangles, take a look at the sample output.
输入
The input contains several testcases. Each is specified by an integer n. Input is terminated by n=0. Otherwise 1<=n<=10 indicates the recursion depth.
输出
For each test case draw an outline of the Sierpinski Triangle with a side's total length of 2ncharacters. Align your output to the left, that is, print the bottom leftmost slash into the first column. The output must not contain any trailing blanks. Print an empty line after each test case.
样例输入
样例输出
/\
/__\
/\ /\
/__\/__\
/\ /\
/__\ /__\
/\ /\ /\ /\
/__\/__\/__\/__\ /\
/__\
/\ /\
/__\/__\ /\
/__\
解题思路
一开始总是以小三角形为单位,百思不得其解。看了一眼网上的思路之后恍然大悟要用数组做,递归的整体过程也写的很轻松,然后被各种换行空字符bug折磨,调了一个多小时orz。
AC代码
#include<iostream>
#include<cstring>
using namespace std; char map[][];//x向上延展是行,y向右延展是列 void GetMap(int t, int x, int y)//x,y是每个三角形的起点
{
if (t == )
{
map[x][y] = '/', map[x][y+] = '_', map[x][y+] = '_', map[x][y+] = '\\';
map[x + ][y] = ' ', map[x + ][y + ] = '/', map[x + ][y + ] = '\\';
}
else
{
GetMap(t - , x, y);
GetMap(t - , x, ( << t) + y);
GetMap(t - , ( << (t - )) + x, ( << (t - )) + y);
}
} void Draw(int t)
{
int m = ( << t) + ;
for (int i = <<t; i > ; i--)
{
for (int j = ; j <= m; j++)
{
if (map[i][j])
{
cout << map[i][j];
}
else cout << ' ';
}
cout << endl;
m++;
}
} int main()
{
int t;
int num = ;
while (true)
{
cin >> t;
if (t == )break;
GetMap(t,,);
if(num > ) cout << endl;
num++;
Draw(t);
}
//system("pause");
return ;
}
POJ 1941 The Sierpinski Fractal的更多相关文章
- poj 1941 The Sierpinski Fractal 递归
//poj 1941 //sep9 #include <iostream> using namespace std; const int maxW=2048; const int maxH ...
- POJ 1941 The Sierpinski Fractal ——模拟
只需要开一个数组,记录一下这个图形. 通过一番计算,发现最大的面积大约是2k*2k的 然后递归下去染三角形. 需要计算出左上角的坐标. 然后输出的时候需要记录一下每一行最远延伸的地方,防止行末空格过多 ...
- POJ1941 The Sierpinski Fractal
Description Consider a regular triangular area, divide it into four equal triangles of half height a ...
- POJ 题目分类(转载)
Log 2016-3-21 网上找的POJ分类,来源已经不清楚了.百度能百度到一大把.贴一份在博客上,鞭策自己刷题,不能偷懒!! 初期: 一.基本算法: (1)枚举. (poj1753,poj2965 ...
- (转)POJ题目分类
初期:一.基本算法: (1)枚举. (poj1753,poj2965) (2)贪心(poj1328,poj2109,poj2586) (3)递归和分治法. (4)递推. ...
- poj分类
初期: 一.基本算法: (1)枚举. (poj1753,poj2965) (2)贪心(poj1328,poj2109,poj2586) (3)递归和分治法. ( ...
- poj 题目分类(1)
poj 题目分类 按照ac的代码长度分类(主要参考最短代码和自己写的代码) 短代码:0.01K--0.50K:中短代码:0.51K--1.00K:中等代码量:1.01K--2.00K:长代码:2.01 ...
- POJ题目分类(按初级\中级\高级等分类,有助于大家根据个人情况学习)
本文来自:http://www.cppblog.com/snowshine09/archive/2011/08/02/152272.spx 多版本的POJ分类 流传最广的一种分类: 初期: 一.基本算 ...
- POJ题目分类(转)
初期:一.基本算法: (1)枚举. (poj1753,poj2965) (2)贪心(poj1328,poj2109,poj2586) (3)递归和分治法. (4)递推. ...
随机推荐
- HTML——MP4视频不能播放
前言 HTML5中提供了video标签,但是为什么有的MP4视频可以播放,有的不能播放呢? 简介 当然是因为编码的问题咯~ 视频格式 标签属性 DOM参考 HTML 5 视频/音频参考手册 使用 &l ...
- presto docker简单试用
starburstdata 团队提供了一个docker 版本的presto,其中已经内置了几个connectors tpch tpcds memory backhole jmx system pull ...
- A revolutionary architecture for building a distributed graph
转自:https://blog.apollographql.com/apollo-federation-f260cf525d21 What if you could access all of you ...
- vue-cli 中的 eslint 规则说明
"no-alert": 0,//禁止使用alert confirm prompt "no-array-constructor": 2,//禁止使用数组构造器 & ...
- C Primer Plus--C预处理器和C库(2)
目录 #include指令 头文件 其他指令 #undef 条件编译 内联函数 #include指令 #include <头文件.h>//在标准系统目录中寻找头文件 #include &q ...
- rabbitmq生产者queue接收不到消息
项目问题: 客户的UAT环境下,项目运行一段时间后,rabbitmq的生产者queue再也接收不到系统发送的消息了.因为queue接收不到消息,所以消费者无法消费数据,流程断掉了. 原因: 客户UAT ...
- SpringMVC(下)
一.访问静态资源 在进行Spring MVC的配置时,通常我们会配置一个dispatcher servlet用于处理对应的URL 在设置url-pattern时可以设置三种形式 (1)/* :拦截所有 ...
- Invalid bound statement (not found) 错误原因
对我来说,错误的原因是因为没有配置:mybatis.mapperLocations=classpath:mybatis/mapper/*Mapper.xmlmybatis.config-locatio ...
- Maven在jar中生成重复的pom.xml和pom.properties文件
eclispe maven打包的时候总是出现"生成的jar的META-INF中,重复的pom.xml和pom.properties文件.",maven命令直接打包则没有这个问题. ...
- sqlite 常用的一些语句
转载:https://blog.csdn.net/qq_25221835/article/details/82768375 转载:https://blog.csdn.net/qq_35449730/a ...