uva 177:Paper Folding(模拟 Grade D)
题意:一张纸,每次从右往左对折。折好以后打开,让每个折痕都自然的呈90度。输出形状。
思路:模拟折……每次折想象成把一张纸分成了正面在下的一张和反面在上的一张。维护左边和方向,然后输出。细节有点多。
代码:
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std; #define N (1<<13)+10 struct Paper{
int l, r;
bool isFace;
Paper(){}
Paper(int _l, int _r, bool is) : l(_l), r(_r), isFace(is){}
}paper[N]; int data[N]; int pp; void flod(Paper &now) {
int mid = (now.l+now.r)/;
data[mid] = now.isFace?:-;
//printf("%d %c %d\n", now.l, "^v"[data[mid]==1], now.r);
if( now.isFace ) {
paper[pp++] = Paper(mid,now.r,!now.isFace);
now.r = mid;
} else {
paper[pp++] = Paper(mid,now.r,now.isFace);
now.r = mid;
now.isFace = !now.isFace;
} } struct Point{
int x,y;
int way;
Point(int x=, int y=, int way=-):x(x),y(y),way(way){}
}point[N]; enum{
R,U,L,D
}; char mat[][];
void showGraph(int end) {
point[] = Point(,,R);
//printf("%d,%d,%c\n",0,0,"RULD"[R]);
int lmost = ;
int umost = ;
int rmost = ;
int dmost = ;
for (int i = ; i < end; i++) {
int way = (point[i-].way+data[i]+)%;
int x = point[i-].x;
int y = point[i-].y; // 细节:找出现在的位置
switch(point[i-].way) {
case R: y += ; break;
case L: y -= ; break;
case U: x -= ; break;
case D: break;
}
switch (way) {
case R: y += ; break;
case L: y -= ; break;
case U: break;
case D: x += ; break;
} point[i] = Point(x, y, way); //printf("%d,%d,%c\n",x,y,"RULD"[way]); umost = min(umost, x);
dmost = max(dmost, x); lmost = min(lmost, y);
rmost = max(rmost, y);
}
//printf(" %d \n%d %d\n %d\n", umost, lmost, rmost, dmost);
memset(mat, ' ', sizeof(mat));
for (int i = ; i < end; i++) {
mat[point[i].x-umost][point[i].y-lmost] = (point[i].way == L || point[i].way == R)?'_':'|';
}
dmost = dmost - umost;
rmost = rmost - lmost;
for (int i = ; i <= dmost; i++) {
mat[i][rmost+] = ;
int p = rmost;
while (mat[i][p] == ' ') mat[i][p--] = ;
printf("%s\n", mat[i]);
}
puts("^");
//printf(" %d \n%d %d\n %d\n", umost, lmost, rmost, dmost);
} int main() {
int n;
while (scanf("%d", &n) != EOF) {
if (n == ) break;
pp = ;
paper[pp++] = Paper(,<<n,true); memset(data, -, sizeof(data));
for (int i = ; i < n; i++) {
int nowpp = pp;
for (int j = ; j < nowpp; j++) {
flod(paper[j]);
}
} //for (int i = 1; i < (1<<n); i++) {
// printf("%c ", "^v"[data[i]==1]);
//}puts(""); showGraph(<<n);
}
return ;
}
uva 177:Paper Folding(模拟 Grade D)的更多相关文章
- Uva - 177 - Paper Folding
If a large sheet of paper is folded in half, then in half again, etc, with all the folds parallel, t ...
- 【uva 177】Paper Folding(算法效率--模拟)
P.S.模拟真の难打,我花了近乎三小时!o(≧口≦)o 模拟题真的要思路清晰!分块调试. 题意:著名的折纸问题:给你一张很大的纸,对折以后再对折,再对折--每次对折都是从右往左折,因此在折了很多次以后 ...
- Paper Folding UVA - 177 模拟+思路+找规律
题目:题目链接 思路:1到4是很容易写出来的,我们先考虑这四种情况的绘制顺序 1:ru 2:rulu 3:rululdlu 4:rululdluldrdldlu 不难发现,相较于前一行,每一次增加一倍 ...
- UVA 1594:Ducci Sequence (模拟 Grade E)
题意: 对于一个n元组(a0,a1,...),一次变换后变成(|a0-a1|,|a1-a2|,...) 问1000次变换以内是否存在循环. 思路: 模拟,map判重 代码: #include < ...
- UVA 1593: Alignment of Code(模拟 Grade D)
题意: 格式化代码.每个单词对齐,至少隔开一个空格. 思路: 模拟.求出每个单词最大长度,然后按行输出. 代码: #include <cstdio> #include <cstdli ...
- UVA 1589:Xiangqi (模拟 Grade D)
题目: 象棋,黑棋只有将,红棋有帅车马炮.问是否死将. 思路: 对方将四个方向走一步,看看会不会被吃. 代码: 很难看……WA了很多发,还越界等等. #include <cstdio> # ...
- UVa 11210 - Chinese Mahjong 模拟, 枚举 难度: 0
题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...
- UVA 1156 - Pixel Shuffle(模拟+置换)
UVA 1156 - Pixel Shuffle 题目链接 题意:依据题目中的变换方式,给定一串变换方式,问须要运行几次才干回复原图像 思路:这题恶心的一比,先模拟求出一次变换后的相应的矩阵,然后对该 ...
- UVA 12050 - Palindrome Numbers 模拟
题目大意:给出i,输出第i个镜像数,不能有前导0. 题解:从外层开始模拟 #include <stdio.h> int p(int x) { int sum, i; ;i<=x;i+ ...
随机推荐
- 在windows和Linux下安装nodejs
在windows下安装nodejs 1.首先下载nodejs安装包, https://nodejs.org/en/download/ 点击下载相应的版本 然后将文件夹解压到安装目录(任意,不做规定) ...
- 2、python中的数字
第二篇开始谈谈python中的数据. 一.前言 python中的数字包含了整数.浮点数.复数三种.在python的早期版本,或许可以看到正数被分为长整数与短整数,后来被取消了,因此这里不作讨论.通常我 ...
- 笔记-python-tutorial-8.errors and exceptions
笔记-python-tutorial-8.errors and exceptions 1. errors and exceptions 1.1. syntax errors >& ...
- MySQL和PostgreSQL比较
1.MySQL相对来说比较年轻,首度出现在1994年.它声称自己是最流行的开源数据库.MySQL就是LAMP(用于Web开发的软件包,包括 Linux.Apache及Perl/PHP/Python)中 ...
- 1250 Fibonacci数列(矩阵乘法快速幂)
1250 Fibonacci数列 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题目描述 Description 定义:f0=f1=1, f ...
- border,border-width不支持百分比
1.border-width不支持百分比 原因:不会因为设备大就按比例变大 同样的,outline,box-shadow,text-shadow也不支持百分比 也就是border不支持百分比 2.bo ...
- phpstorm将本地代码传递到远程服务器
由于对vim不太熟悉,效率比较低,作为过渡阶段,采用本地编写代码,然后上传到开发机上,进行调试 前提是服务器开启了ftp服务:http://www.cnblogs.com/redirect/p/693 ...
- Azure Active Directory Connect是如何协助管理员工作的?
TechTarget中国原创] 应用基于云的Microsoft Azure Active Directory,管理员们可以将本地Active Directory整合到Windows Server中.通 ...
- leetcode 【 Remove Element 】python 实现
题目: Given an array and a value, remove all instances of that value in place and return the new lengt ...
- python正则表达式应用优化实例
1.问题出现 需要提取一份xml文件中参数名和参数值,格式如下: <p name="actOlLaPdcch">true</p> 我们需要的字段如上,红色部 ...