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)递推. ...
随机推荐
- 项目Alpha冲刺(团队)-总结篇
格式描述 课程名称:软件工程1916|W(福州大学) 作业要求:项目Alpha冲刺(团队)-代码规范.冲刺任务与计划 团队名称:为了交项目干杯 作业目标:描述项目预期计划.现实进展.过程体会.组员分工 ...
- 更新GitHub上自己 Fork 的代码与原作者的项目进度一致
在GitHub上我们会去fork别人的一个项目,这就在自己的Github上生成了一个与原作者项目互不影响的副本,自己可以将自己Github上的这个项目再clone到本地进行修改,修改后再push,只有 ...
- Java项目使用 Tomcat 部署 Linux 服务器
一.安装 Java 环境 1 下载 jdk 8 yum -y install java-1.8.0-openjdk java-1.8.0-openjdk-devel 设置 centos7 环境变量 v ...
- learning scala akka tell pattern(二)
package com.example import akka.actor._ object Tutorial_02_Tell_Pattern extends App { println(" ...
- tomcat 配置更改 web 目录
tomcat 虚拟目录:( 编辑 tomcat/conf/server.xml ) <Host name="localhost" appBase="webapps ...
- ServiceStack.OrmLite 基本操作
原文:https://www.cnblogs.com/wang2650/category/780821.html 原文:https://www.cnblogs.com/xxfcz/p/7045808. ...
- Gift to XBACK(小小礼物)
什么白天 什么黑夜 我没有 准备着给你的 Surprise 你给我的爱 让我觉得已足够 是你让我相信爱会有 是你的爱陪我绕宇宙 打开日记本写下忧愁 你却让我看时间轴 我才知道现在我能看到的画面 拥有你 ...
- centos7中运行ifconfig提示-bash: ifconfig: command not found
centos7中运行ifconfig提示-bash: ifconfig: command not found 查看/sbin/下是否有ifconfig,若没有通过如下命令安装 sudo yum ins ...
- 【整理】Xcode中的iOS模拟器(iOS Simulator)的介绍和使用心得
[整理]Xcode中的iOS模拟器(iOS Simulator)的介绍和使用心得 iOS模拟器简介 iOS功能简介 iOS模拟器,是在Mac下面开发程序时,开发iOS平台的程序时候,可以使用的辅助工具 ...
- CF1221F Choose a Square(二维偏序)
由于y=x,我们可以将点对称过来,以便(x,y)(x<y) 考虑选取正方形(a,a,b,b),点集则为\((a\le x\le y\le b)\),相当于二维数点 将点按x降序,y升序排列,线段 ...