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+ ...
随机推荐
- wampserver怎么设置外网可访问
wampserver配置httpd.conf允许外网访问? 在电脑上开启wamp服务后,默认是禁止外部网络访问的,如果您想要同一局域网中的设备能够访问PC上的web项目,则需要对httpd.conf文 ...
- 动态规划:HDU1712-ACboy needs your help(分组背包问题)
ACboy needs your help Time Limit : 1000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Othe ...
- U1
如果 activity_main.xml没有xml代码可以对图像右键 go to mxl同时可以在design 和 text 切换 在安装了Android Studio3.3版本之后,第一个He ...
- Java面向对象---类
类的定义 class 类名称{ 变量: 方法: } 声明一个类需要一个关键字:class 类的命名规则:组成类名称的所有单词首字母都必须大写.如UserDao
- 使用tensorflow设计的网络模型看不到数据流向怎么办
首先tensorflow的设计思想就是先把需要用的变量已张量的形式保存, 实际上并没有实质的数值填充. 然后设计网络架构,也仅仅是架构而已, 只能说明数据关系和层与层之间的关系. 真正的数据输入是在主 ...
- Django 三—— Form组件
内容概要: 1.Django Form如何自定义验证字段 2.Django Form如何动态的显示数据库中新插入的数据 3.Tyrion Django的Form(用于验证用户请求合法性的一个组件) D ...
- luogu2120 [ZJOI2007]仓库建设
大米饼写的太棒辣qwqqwq #include <iostream> #include <cstdio> using namespace std; typedef long l ...
- 手机APP设计网
http://hao.xueui.cn/ http://www.25xt.com/
- python - 接口自动化测试 - TestRecharge - 充值接口测试用例
# -*- coding:utf-8 -*- ''' @project: ApiAutoTest @author: Jimmy @file: test_recharge.py @ide: PyChar ...
- Python 拓展之详解深拷贝和浅拷贝
正式开始 首先我在这介绍两个新的小知识,要在下面用到.一个是函数 id() ,另一个是运算符 is.id() 函数就是返回对象的内存地址:is 是比较两个变量的对象引用是否指向同一个对象,在这里请不要 ...