只需要开一个数组,记录一下这个图形。

通过一番计算,发现最大的面积大约是2k*2k的

然后递归下去染三角形。

需要计算出左上角的坐标。

然后输出的时候需要记录一下每一行最远延伸的地方,防止行末空格过多。

然后需要用putchar

#include <map>
#include <cmath>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define F(i,j,k) for (int i=j;i<=k;++i)
#define D(i,j,k) for (int i=j;i>=k;--i)
#define ll long long
#define mp make_pair
#define maxn 2050 char s[maxn][maxn]; int l[11]={0,4,8,16,32,64,128,256,512,1024,2048},n,h[11]={0,2,4,8,16,32,64,128,256,512,1024};
int upper[maxn],high=0; inline void solve(int x,int y,int siz)
{
if (!siz) return;
if (siz==1)
{
s[x][y]=' ';
s[x][y+1]='/';
s[x][y+2]='\\';
s[x+1][y]='/';
s[x+1][y+3]='\\';
s[x+1][y+1]='_';
s[x+1][y+2]='_';
upper[x]=max(upper[x],y+2);
upper[x+1]=max(upper[x],y+3);
high=max(high,x+1);
return ;
}
F(i,x,x+h[siz-1]-1) F(j,y,l[siz-1]/2+y-1) s[i][j]=' ';
solve(x,y+l[siz-1]/2,siz-1);
solve(x+h[siz-1],y,siz-1);
solve(x+h[siz-1],y+l[siz-1],siz-1);
} int main()
{
while(scanf("%d",&n)!=EOF&&n)
{
F(i,0,h[n]) F(j,0,l[n]) s[i][j]=' ';
high=0;memset(upper,0,sizeof upper);
solve(0,0,n);
F(i,0,high)
{
F(j,0,upper[i]) putchar(s[i][j]);
putchar('\n');
}
putchar('\n');
}
}

  

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

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

  3. POJ1941 The Sierpinski Fractal

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

  4. poj 1008:Maya Calendar(模拟题,玛雅日历转换)

    Maya Calendar Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 64795   Accepted: 19978 D ...

  5. POJ 1027 The Same Game(模拟)

    题目链接 题意 : 一个10×15的格子,有三种颜色的球,颜色相同且在同一片内的球叫做cluster(具体解释就是,两个球颜色相同且一个球可以通过上下左右到达另一个球,则这两个球属于同一个cluste ...

  6. POJ 3414 Pots【bfs模拟倒水问题】

    链接: http://poj.org/problem?id=3414 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22009#probl ...

  7. poj 2632 Crashing Robots(模拟)

    链接:poj 2632 题意:在n*m的房间有num个机器,它们的坐标和方向已知,现给定一些指令及机器k运行的次数, L代表机器方向向左旋转90°,R代表机器方向向右旋转90°,F表示前进,每次前进一 ...

  8. poj 1028 Web Navigation(模拟)

    题目链接:http://poj.org/problem? id=1028 Description Standard web browsers contain features to move back ...

  9. POJ 3087 Shuffle'm Up (模拟+map)

    题目链接:http://poj.org/problem?id=3087 题目大意:已知两堆牌s1和s2的初始状态, 其牌数均为c,按给定规则能将他们相互交叉组合成一堆牌s12,再将s12的最底下的c块 ...

随机推荐

  1. 2018.7.1 css项目之模仿满屋花首页css+idv布局实现

    可以分开写 <!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF ...

  2. Github的基本功能

    著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处.作者:Fadeoc Khaos链接:http://www.zhihu.com/question/20070065/answer/30 ...

  3. C++ 限定名称查找

    限定名称查找规则实际归纳下来很简单,先对::左边的名称进行查找(遵循,限定,无限定),然后在左边查找到的(此时只查找类型名称)名字的作用域内(含内联名称空间件)查找右边出现的名字,查找到即存在(故可以 ...

  4. unix环境高级编程一书中部分错误处理函数

    #include <unistd.h> #include <errno.h> #include <string.h> #include <stdio.h> ...

  5. pycahrm git配置笔记

    1. 在file - setting - plugins 中查看是否有github插件, 此处是用于处理插件位置

  6. 用户和用户组以及 Linux 权限管理

    1.从 /etc/passwd 说起 前面的基本命令学习中,我们介绍了使用 passwd 命令可以修改用户密码.对于操作系统来说,用户名和密码是存放在哪里的呢?我们都知道一个站点的用户名和密码是存放在 ...

  7. 【bug】【yii】配置log时,报错 Setting read-only property: yii\web\Application::log

    Setting read-only property: yii\web\Application::log 配置放在了 components 外面,应该放在里面

  8. JZOJ 1266. 玉米田

    1266. 玉米田(cowfood.pas/c/cpp) (File IO): input:cowfood.in output:cowfood.out Time Limits: 1000 ms  Me ...

  9. bootmem_free_node

    该函数设置: 1.pgdata节点的成员 2.pgdata->zone的成员 3.初始化zone->free_area 4.初始化zone所包含的所有页对应的页框描述符page结构体 /* ...

  10. 各种友(e)善(xin)数论总集(未完待续),从入门到绝望

    目录 快速幂 扩展欧几里得 GCD 扩展欧几里得 同余系列 同余方程 同余方程组 一点想法 高次同余方程 BSGS exBSGS 线性筛素数 埃式筛 欧拉筛 欧拉函数 讲解 两道水题 法雷级数 可见点 ...