Description

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.

Input

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.

Output

For each test case draw an outline of the Sierpinski Triangle with a side's total length of 2n
characters. 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.

Sample Input

3
2
1
0

Sample Output

       /\
/__\
/\ /\
/__\/__\
/\ /\
/__\ /__\
/\ /\ /\ /\
/__\/__\/__\/__\ /\
/__\
/\ /\
/__\/__\ /\
/__\

Hint


The Sierpinski-Triangle up to recursion depth 7

Source

 
 
 
正解:模拟
解题报告:
  北大夏令营考过这道题,然而我没有做出来,当时真是傻了。
  递归构造字符,注意多余的要输出空格。
  看一下代码中的细节吧。
 
 //It is made by jump~
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <ctime>
#include <vector>
#include <queue>
#include <map>
#include <set>
using namespace std;
typedef long long LL;
char ch[][];
int n; inline int getint()
{
int w=,q=; char c=getchar();
while((c<'' || c>'') && c!='-') c=getchar(); if(c=='-') q=,c=getchar();
while (c>='' && c<='') w=w*+c-'', c=getchar(); return q ? -w : w;
} inline void solve(int x,int y,int now){
if(now==) {
ch[x][y]='/'; ch[x][y+]='_'; ch[x][y+]='_'; ch[x][y+]='\\';
ch[x-][y+]='/'; ch[x-][y+]='\\';
return ;
}
int du=(<<now);//拆分成三个小三角形
solve(x,y,now-); solve(x,y+du,now-); solve(x-du/,y+du/,now-);
} inline void work(){
while() {
n=getint(); if(n==) break;
memset(ch,,sizeof(ch)); int mi=(<<n);
solve(mi,,n); int last;//记录最后一个
for(int i=;i<=mi;i++) {
for(int j=;j<mi*;j++) if(ch[i][j]) last=j;
for(int j=;j<last;j++) if(!ch[i][j]) ch[i][j]=' ';
}
for(int i=;i<=mi;i++) printf("%s\n",ch[i]);
printf("\n");
}
} int main()
{
work();
return ;
}

POJ1941 The Sierpinski Fractal的更多相关文章

  1. POJ 1941 The Sierpinski Fractal

    总时间限制: 1000ms 内存限制: 65536kB 描述 Consider a regular triangular area, divide it into four equal triangl ...

  2. poj 1941 The Sierpinski Fractal 递归

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

  3. POJ 1941 The Sierpinski Fractal ——模拟

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

  4. POJ 题目分类(转载)

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

  5. HDU——PKU题目分类

    HDU 模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 ...

  6. (转)POJ题目分类

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

  7. poj分类

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

  8. 转载 ACM训练计划

    leetcode代码 利用堆栈:http://oj.leetcode.com/problems/evaluate-reverse-polish-notation/http://oj.leetcode. ...

  9. poj 题目分类(1)

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

随机推荐

  1. [推荐] BC/Beyond Compare(差异比较软件)

    Beyond Compare 前一段时间,介绍过用Total Commander来完成文件夹同步的时候,一位朋友留言推荐了Beyond Compare--一个强大的超越了文件差异比较的工具.Beyon ...

  2. Windows远程桌面连接Ubuntu 14.04

    由于xrdp.gnome和unity之间的兼容性问题,在Ubuntu 14.04版本中仍然无法使用xrdp登陆gnome或unity的远程桌面,现象是登录后只有黑白点为背景,无图标也无法操作.与13. ...

  3. Java 枚举活用

    /** * 联盟神兽.神兽资源枚举 * * @author TonyCody * @author 13-9-22 * @time 下午5:35 */ public enum LegionDogzTyp ...

  4. ArcGis 中MapControl 框选

    void mCtrl_OnMouseDown(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseDownEvent e)    ...

  5. javascript中的数组操作

    1.数组的创建 var arrayObj = new Array(); //创建一个数组 var arrayObj = new Array([size]); //创建一个数组并指定长度,注意不是上限, ...

  6. Could not publish server configuration for MyEclipse Tomcat v7.0. Multiple Contexts have a path

    Could not publish server configuration for Tomcat v6.0 Server at localhost. 经常在使用tomcat服务器的时候 总会发生一些 ...

  7. 第二章 时间控件(DateTime Picker)

    这家伙太懒了,碰到问题才写博文,嘿嘿. 好了进入正题,二话不说,先放地址: 中文:http://www.bootcss.com/p/bootstrap-datetimepicker/index.htm ...

  8. Bolts-Android

    对Android客户端编程来说,有个明确的规则是不能在ui线程里面做耗时的操作.这样就要求网络请求.文件读写等等操作都要异步操作.而异步操作完成后,往往需要再更新ui界面.最直接的想法是回调,只要保证 ...

  9. 【C#】ContextMenuStrip 右键菜单颜色设置

    有些时候自己想要修改ContexMenuStrip右键菜单的一些背景色之类的,该如何实现呢? 首先: ContextMenuStrip _context = new ContextMenuStrip( ...

  10. [IPSEC PKI]

    PKI: 对称加密 非对称加密(混合加密) 数字签名   理论概述: (1)预备知识 对称加密:加密密钥和揭秘蜜钥是同一个密钥 缺点:不适合在互联网上传输密钥 密钥维护工作量大 n(n-1)/2 : ...