总时间限制: 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的更多相关文章

  1. poj 1941 The Sierpinski Fractal 递归

    //poj 1941 //sep9 #include <iostream> using namespace std; const int maxW=2048; const int maxH ...

  2. POJ 1941 The Sierpinski Fractal ——模拟

    只需要开一个数组,记录一下这个图形. 通过一番计算,发现最大的面积大约是2k*2k的 然后递归下去染三角形. 需要计算出左上角的坐标. 然后输出的时候需要记录一下每一行最远延伸的地方,防止行末空格过多 ...

  3. POJ1941 The Sierpinski Fractal

    Description Consider a regular triangular area, divide it into four equal triangles of half height a ...

  4. POJ 题目分类(转载)

    Log 2016-3-21 网上找的POJ分类,来源已经不清楚了.百度能百度到一大把.贴一份在博客上,鞭策自己刷题,不能偷懒!! 初期: 一.基本算法: (1)枚举. (poj1753,poj2965 ...

  5. (转)POJ题目分类

    初期:一.基本算法:     (1)枚举. (poj1753,poj2965)     (2)贪心(poj1328,poj2109,poj2586)     (3)递归和分治法.     (4)递推. ...

  6. poj分类

    初期: 一.基本算法:      (1)枚举. (poj1753,poj2965)      (2)贪心(poj1328,poj2109,poj2586)      (3)递归和分治法.      ( ...

  7. poj 题目分类(1)

    poj 题目分类 按照ac的代码长度分类(主要参考最短代码和自己写的代码) 短代码:0.01K--0.50K:中短代码:0.51K--1.00K:中等代码量:1.01K--2.00K:长代码:2.01 ...

  8. POJ题目分类(按初级\中级\高级等分类,有助于大家根据个人情况学习)

    本文来自:http://www.cppblog.com/snowshine09/archive/2011/08/02/152272.spx 多版本的POJ分类 流传最广的一种分类: 初期: 一.基本算 ...

  9. POJ题目分类(转)

    初期:一.基本算法:     (1)枚举. (poj1753,poj2965)     (2)贪心(poj1328,poj2109,poj2586)     (3)递归和分治法.     (4)递推. ...

随机推荐

  1. SQL操作Spark SQL--BasicSQLTestt

    object BasicSQLTest { def main(args: Array[String]): Unit = { val spark = SparkSession .builder() .a ...

  2. sqler 集成 terraform v0.12 生成资源部署文件

    terraform v0.12 发布了,有好多新功能的添加,包括语法的增强,新函数的引入,更好的开发提示 只是当前对于一些老版本的provider 暂时还不兼容,但是大部分官方的provider 都是 ...

  3. 47、Spark SQL核心源码深度剖析(DataFrame lazy特性、Optimizer优化策略等)

    一.源码分析 1. ###入口org.apache.spark.sql/SQLContext.scala sql()方法: /** * 使用Spark执行一条SQL查询语句,将结果作为DataFram ...

  4. uni-app input text-indent失效解决

    有两种方法去解决 第一种 input { padding-left: 10upt } 第二种 input { display: block }

  5. 「2019-8-11提高模拟赛」女装盛宴 (flag)

    传送门 Solution  基环树+倍增+双指针 第一次因为#define int long long而玄学RE 为什么标程都不用开\(long long\)啊 Code  /*玄学RE 看来defi ...

  6. 微信小程序 movable-view组件应用:可拖动悬浮框_返回首页

    1. movable-view组件具体内容可参考官网:微信官方文档 2. demo参考:https://github.com/ChinaFanny/YFWeappMovableView 运行效果 核心 ...

  7. 【Codeforces】CF367D Sereja and Sets (数学)

    题目大意 1到n这n个正整数被分成了m个不相交的集合(集合不一定连续),现在从这m个集合中选出最少个数的集合,满足对于[1,n]中任意一个长度为d的区间都至少有一个数字出现在已选集合中.(1 < ...

  8. mysql的动态表名

    create EVENT createMtpulseTable ON SCHEDULE every 1 month STARTS CURRENT_TIMESTAMP DO CALL pro_creat ...

  9. 解决Shell脚本$'\r': command not found问题

    造成这个问题的原因是Windows下的空行,我们只需要把文件转成unix就好 Centos下,执行yum install dos2unix,然后dos2unix [file],再执行shell命令就好 ...

  10. centos7下配置ftp服务器

    第一步,安装vsftpd这款ftp服务器软件,yum install -y vsftpd 第二步,设置vsftpd服务开机自启动,然后重启服务,查看ftp服务端口,centos6命令如下: #chkc ...