POJ 1941 The Sierpinski Fractal ——模拟
只需要开一个数组,记录一下这个图形。
通过一番计算,发现最大的面积大约是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 ——模拟的更多相关文章
- 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
总时间限制: 1000ms 内存限制: 65536kB 描述 Consider a regular triangular area, divide it into four equal triangl ...
- POJ1941 The Sierpinski Fractal
Description Consider a regular triangular area, divide it into four equal triangles of half height a ...
- poj 1008:Maya Calendar(模拟题,玛雅日历转换)
Maya Calendar Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 64795 Accepted: 19978 D ...
- POJ 1027 The Same Game(模拟)
题目链接 题意 : 一个10×15的格子,有三种颜色的球,颜色相同且在同一片内的球叫做cluster(具体解释就是,两个球颜色相同且一个球可以通过上下左右到达另一个球,则这两个球属于同一个cluste ...
- POJ 3414 Pots【bfs模拟倒水问题】
链接: http://poj.org/problem?id=3414 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22009#probl ...
- poj 2632 Crashing Robots(模拟)
链接:poj 2632 题意:在n*m的房间有num个机器,它们的坐标和方向已知,现给定一些指令及机器k运行的次数, L代表机器方向向左旋转90°,R代表机器方向向右旋转90°,F表示前进,每次前进一 ...
- poj 1028 Web Navigation(模拟)
题目链接:http://poj.org/problem? id=1028 Description Standard web browsers contain features to move back ...
- POJ 3087 Shuffle'm Up (模拟+map)
题目链接:http://poj.org/problem?id=3087 题目大意:已知两堆牌s1和s2的初始状态, 其牌数均为c,按给定规则能将他们相互交叉组合成一堆牌s12,再将s12的最底下的c块 ...
随机推荐
- 2018.6.10 Oracle数据库常见的错误汇总
1.ClassNoFoundException 找不到注册驱动 可能原因:1>驱动名称不对 2>没有导入数据库驱动包 2.SQl 语句中可以使用任何有效的函数,函数操作的列,必须指定别名, ...
- 跟我一起从零开始学WCF系列课程
http://www.microsoft.com/china/msdn/events/webcasts/shared/webcast/Series/WCF_Begin.aspx 服务和协定 服务协定使 ...
- 用gulp把less文件编译成css文件
第一次使用gulp构建工具,使用gulp将.less文件编译成.css文件并输出.根据视频做了笔记.提供新手和自己以后做参考. HTML文件 <!DOCTYPE html> <htm ...
- Node第二天
一.http模块: 步骤一:创建http服务器 const https = require('https'); 步骤二:const fs = require('fs'); 步骤三:创建请求=> ...
- 1037: [ZJOI2008]生日聚会Party
Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 3121 Solved: 1858[Submit][Status][Discuss] Descript ...
- django+xadmin在线教育平台(六)
4-1 使用py3.6和django1.11开发系统前注意事项 直接通过Python3.6和django最新版本来开发我们的系统的一些注意事项. 原版本: Python 2.7 & djang ...
- 42.VUE学习之--组件之子组件使用$on与$emit事件触发父组件实现购物车功能
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- [译]The Python Tutorial#2. Using the Python Interpreter
[译]The Python Tutorial#Using the Python Interpreter 2.1 Invoking the Interpreter Python解释器通常安装在目标机器的 ...
- Tricky Sum
In this problem you are to calculate the sum of all integers from 1 to n, but you should take all po ...
- Linux命令之---ls
命令简介: ls(list)命令用来列出目标目录(缺省的话为当前目录)中所有的子目录和文件. 指令所在路径:/bin/ls 执行权限:All User 命令语法: ls [选项] [目录名] 命令参数 ...