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

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 ...
随机推荐
- github结合TortoiseGit使用sshkey,无需输入账号和密码
1.github上支持三种方式进行项目的clone https,ssh,subversion https://github.com/用户名/版本库.git ssh的方式 git@github.c ...
- [C#] 委托之Action和Func区别
一.说明 一般我们定义委托都是有如下两步: public delegate void MyDelegate(string name);//定义委托 public MyDelegate myDelega ...
- android 知识点收集
1. 计算时间流逝请使用SystemClock.elapsedRealtime... currentTimeMillis会受系统时钟影响 //未验证 2. android app私有文件的目录 ...
- Gruntjs: task之文件映射
由于大多数的任务执行文件操作,Grunt提供了一个强大的抽象声明说明任务应该操作哪些文件.这里总结了几种src-dest(源文件-目标文件)文件映射的方式,提供了不同程度的描述和控制操作方式. 1. ...
- [CareerCup] 8.10 Implement a Hash Table 实现一个哈希表
8.10 Design and implement a hash table which uses chaining (linked lists) to handle collisions. 这道题让 ...
- 20145208 《Java程序设计》第4周学习总结
20145208 <Java程序设计>第4周学习总结 教材学习内容总结 继承 在学习指导中我了解到继承是符合DRY原则的,DRY(Don't repeat yourself),字面意思来看 ...
- 不得不说的JavaScript异步加载
同步加载的问题 默认的js是同步加载的,这里的“加载”可以理解成是解析.执行,而不是“下载”,在最新版本的浏览器中,浏览器对于代码请求的资源都是瀑布式的加载,而不是阻塞式的,但是js的执行总是阻塞的. ...
- Html中metra的含义
from: http://dev.csdn.net/article/60/60902.shtm meta是用来在HTML文档中模拟HTTP协议的响应头报文.meta 标签用于网页的<head&g ...
- mod mono xsp
Mod_Mono 是Apache的一个扩展模块,使得apache支持asp.net. 该模块传递asp.net的请求到一个额外的程序 mod-mono-server(该程序是在安装xsp的时候自动安装 ...
- http长链接与短链接
http://www.cnblogs.com/cswuyg/p/3653263.html keep-live模式 这个博客写的很全:http://www.cnblogs.com/skynet/arch ...