POJ1941 The Sierpinski Fractal
Description
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
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
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
![](http://poj.org/images/1941_1.jpg)
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的更多相关文章
- POJ 1941 The Sierpinski Fractal
总时间限制: 1000ms 内存限制: 65536kB 描述 Consider a regular triangular area, divide it into four equal triangl ...
- 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的 然后递归下去染三角形. 需要计算出左上角的坐标. 然后输出的时候需要记录一下每一行最远延伸的地方,防止行末空格过多 ...
- POJ 题目分类(转载)
Log 2016-3-21 网上找的POJ分类,来源已经不清楚了.百度能百度到一大把.贴一份在博客上,鞭策自己刷题,不能偷懒!! 初期: 一.基本算法: (1)枚举. (poj1753,poj2965 ...
- HDU——PKU题目分类
HDU 模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 ...
- (转)POJ题目分类
初期:一.基本算法: (1)枚举. (poj1753,poj2965) (2)贪心(poj1328,poj2109,poj2586) (3)递归和分治法. (4)递推. ...
- poj分类
初期: 一.基本算法: (1)枚举. (poj1753,poj2965) (2)贪心(poj1328,poj2109,poj2586) (3)递归和分治法. ( ...
- 转载 ACM训练计划
leetcode代码 利用堆栈:http://oj.leetcode.com/problems/evaluate-reverse-polish-notation/http://oj.leetcode. ...
- poj 题目分类(1)
poj 题目分类 按照ac的代码长度分类(主要参考最短代码和自己写的代码) 短代码:0.01K--0.50K:中短代码:0.51K--1.00K:中等代码量:1.01K--2.00K:长代码:2.01 ...
随机推荐
- Android系列之网络(二)----HTTP请求头与响应头
[声明] 欢迎转载,但请保留文章原始出处→_→ 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http://www.cnblogs.com/smyhvae/p/ ...
- 测试 Mono 安装
测试 Mono 安装 为了测试核心编译器(mcs)和运行时(mono),应该创建一个简单的程序并编译它.可以在喜欢的任何文本编辑器中创建程序.这里采用一种快速而简陋的方法创建该文件(虽然没有任何格式化 ...
- C# 程序性能提升篇-1、装箱和拆箱,枚举的ToString浅析
前景提要: 编写程序时,也许你不经意间,就不知不觉的使程序代码,发生了装箱和拆箱,从而降低了效率,不要说就发生那么一次两次,如果说是程序中发生了循环.网络程序(不断请求处理的)等这些时候,减少装箱和拆 ...
- emberjs重写补充类之reopen方法和reopenClass方法
无需一次性将类定义完全,你可以使用reopen方法来重新打开(reopen)一个类并为其定义新的属性. Person.reopen({ isPerson: true }); Person.create ...
- javascript中的后退和刷新
<input type=button value=刷新 onclick="window.location.reload()"><input type=button ...
- DevExpress主从表 按组分页一组不足一页为一页--以此记录
本文的主要是说明Dev的报表的主从表,主从表的每一组显示在一页,当一组超出一页,第二页只显示第一组的. 一.每上报表设置图 简单设计图如上 二.后台代码 报表页代码 public partial cl ...
- SpringMVC中的@PathVariable
@PathVariable是用来动态获得url中的参数的,代码示例如下: 可以在代码中获得lev_1.lev_2和target参数的值看一下 // 支持跳转到WEB-INF/目录下二层目录 @Requ ...
- JS 禁用和重新启用a标签的点击事件
function changeHomePageModule(){ var css = $('#collapseExample').attr('class'); if(css=='collapse'){ ...
- MySQL基础 - 编码设置
刚开始工作的时候,在工作中遇到的与数据库相关的问题,多半跟编码有关,总结一下数据库编码的设置. 字符集 查看数据库支持的字符集: mysql> SHOW CHARACTER SET; 从图中可以 ...
- Qt——树的搜索
一.Qt中的树 Qt中树的实现有两种方式.第一种是使用Qt提供的QTreeWidget,很多函数都封装好,比较方便:另一种是通过QTreeView实现,设置它的数据模型,比如使用QStandardIt ...