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:

  1. /\

  2. /__\

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

  1. 3
  2. 2
  3. 1
  4. 0

Sample Output

  1. /\
  2. /__\
  3. /\ /\
  4. /__\/__\
  5. /\ /\
  6. /__\ /__\
  7. /\ /\ /\ /\
  8. /__\/__\/__\/__\
  9.  
  10. /\
  11. /__\
  12. /\ /\
  13. /__\/__\
  14.  
  15. /\
  16. /__\

Hint


The Sierpinski-Triangle up to recursion depth 7

Source

 
 
 
正解:模拟
解题报告:
  北大夏令营考过这道题,然而我没有做出来,当时真是傻了。
  递归构造字符,注意多余的要输出空格。
  看一下代码中的细节吧。
 
  1. //It is made by jump~
  2. #include <iostream>
  3. #include <cstdlib>
  4. #include <cstring>
  5. #include <cstdio>
  6. #include <cmath>
  7. #include <algorithm>
  8. #include <ctime>
  9. #include <vector>
  10. #include <queue>
  11. #include <map>
  12. #include <set>
  13. using namespace std;
  14. typedef long long LL;
  15. char ch[][];
  16. int n;
  17.  
  18. inline int getint()
  19. {
  20. int w=,q=; char c=getchar();
  21. while((c<'' || c>'') && c!='-') c=getchar(); if(c=='-') q=,c=getchar();
  22. while (c>='' && c<='') w=w*+c-'', c=getchar(); return q ? -w : w;
  23. }
  24.  
  25. inline void solve(int x,int y,int now){
  26. if(now==) {
  27. ch[x][y]='/'; ch[x][y+]='_'; ch[x][y+]='_'; ch[x][y+]='\\';
  28. ch[x-][y+]='/'; ch[x-][y+]='\\';
  29. return ;
  30. }
  31. int du=(<<now);//拆分成三个小三角形
  32. solve(x,y,now-); solve(x,y+du,now-); solve(x-du/,y+du/,now-);
  33. }
  34.  
  35. inline void work(){
  36. while() {
  37. n=getint(); if(n==) break;
  38. memset(ch,,sizeof(ch)); int mi=(<<n);
  39. solve(mi,,n); int last;//记录最后一个
  40. for(int i=;i<=mi;i++) {
  41. for(int j=;j<mi*;j++) if(ch[i][j]) last=j;
  42. for(int j=;j<last;j++) if(!ch[i][j]) ch[i][j]=' ';
  43. }
  44. for(int i=;i<=mi;i++) printf("%s\n",ch[i]);
  45. printf("\n");
  46. }
  47. }
  48.  
  49. int main()
  50. {
  51. work();
  52. return ;
  53. }

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. javascript中的时间处理

    var myDate = new Date(); myDate.getYear(); //获取当前年份(2位) myDate.getFullYear(); //获取完整的年份(4位,1970-???? ...

  2. gridpanel分组汇总

    [ExtJS5学习笔记]第三十节 sencha extjs 5表格gridpanel分组汇总 2015-05-31     86 本文地址:http://blog.csdn.net/sushengmi ...

  3. C语言 百炼成钢13

    //题目37:将一个数组逆序输出.用第一个与最后一个交换. #include<stdio.h> #include<stdlib.h> #include<math.h> ...

  4. 通过 SQL Server 视图访问另一个数据库服务器表的方法

    今天项目经理跑过来对我大吼大叫说什么之前安排让我做一大堆接口为什么没做,我直接火了,之前明明没有这个事情…… 不过事情还要解决,好在两个项目都是用的sqlserver,可以通过跨数据库视图来快速解决问 ...

  5. 2015国产犯罪传记《暴力天使》HD720P.泰语中字

    导演: 吴强编剧: 阮明玉主演: 张玉英 / 金理 / 至宝类型: 传记语言:泰语制片国家/地区: 中国大陆上映日期: 2016年3月25日片长: 92分钟又名: Huong Ga暴力天使的剧情简介 ...

  6. 流媒体技术之RTSP

    流媒体技术之RTSP 标签: RTSP技术移动流媒体 2016-06-19 18:48 38人阅读 评论(0) 收藏 举报  分类: 流媒体相关技术 版权声明:本文为博主原创文章,未经博主允许不得转载 ...

  7. 第10章 系统级I/O

    第10章 系统级I/O 10.1 Unix I/O 一个Unix文件就是一个m个字节的序列:B0,B1,…,BK,…,Bm-1 Unix I/O:一种将设备优雅地映射为文件的方式,允许Unix内核引出 ...

  8. HTML5 全屏特性

    全屏功能是浏览器很早就支持的一项功能了,可以让你页面中的video, image ,div 等等子元素实现全屏浏览,从而带来更好的视觉体验,来看看怎么使用吧.先来看看有哪些API和事件支持. API ...

  9. 20145215《Java程序设计》第10周学习总结

    20145215<Java程序设计>第十周学习总结 教材学习内容总结 网络编程 网络概述 网络编程就是在两个或两个以上的设备(例如计算机)之间传输数据.程序员所作的事情就是把数据发送到指定 ...

  10. IT男的”幸福”生活"系列暂停更新通知

    首先谢谢博客园,这里给了我很多快乐.更给了大家一个学习的好地方. 在这几天更新过程中,看到了很多哥们的关注,在这里我谢谢你们,是你们给了我动力,是你们又一次给了我不一样的幸福. 在续5中我已回复了,博 ...