Paper Folding UVA - 177 模拟+思路+找规律
题目:题目链接
思路:1到4是很容易写出来的,我们先考虑这四种情况的绘制顺序
1:ru
2:rulu
3:rululdlu
4:rululdluldrdldlu
不难发现,相较于前一行,每一次增加一倍数量,并且增加的这部分前一半和原来正好相反,后一半相同,根据这一性质,预处理出极端情况13的解答字符串,然后绘制即可,注意控制行尾空格
AC代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque> #define FRER() freopen("in.txt", "r", stdin)
#define FREW() freopen("out.txt", "w", stdout) #define INF 0x3f3f3f3f using namespace std; char ans[], _map[][];
int _max[]; char cal(char ch) {
if(ch == 'l')
return 'r';
if(ch == 'r')
return 'l';
if(ch == 'u')
return 'd';
if(ch == 'd')
return 'u';
} int main()
{
//FRER();
//FREW();
ios::sync_with_stdio();
cin.tie(); ans[] = 'r';
ans[] = 'u';
for(int i = ; i < ; ++i) {
int n = << (i - ), m = << (i - );
for(int j = ; j < n; ++j) {
ans[j + m] = cal(ans[j]);
}
for(int j = ; j < << (i - ); ++j) {
ans[j + m + n] = ans[j + n];
}
}
ans[ << ] = '\0';
cout << ans << endl;
int n;
while(cin >> n, n) {
memset(_map, , sizeof(_map));
memset(_max, , sizeof(_max));
int minl = , maxl = , minc = , maxc = ;
int l = , c = ;
int m = << n;
_max[] = ;
_map[l][c] = '_';
for(int i = ; i < m; ++i) {
if(ans[i - ] == 'l')
--c;
else if(ans[i - ] == 'r')
++c;
else if(ans[i - ] == 'u')
--l; if(ans[i] == 'u') { _map[l][c] = '|';
}
else if(ans[i] == 'd') {
++l;
_map[l][c] = '|';
}
else if(ans[i] == 'l') {
--c;
_map[l][c] = '_';
}
else {
++c;
_map[l][c] = '_';
}
minl = min(minl, l);
minc = min(minc, c);
maxl = max(maxl, l);
_max[l] = max(_max[l], c);
}
for(int i = minl; i <= maxl; ++i) {
for(int j = minc; j <= _max[i]; ++j)
cout << (_map[i][j] == ? ' ' : _map[i][j]);
cout << endl;
}
cout << '^' << endl;
}
return ;
}
Paper Folding UVA - 177 模拟+思路+找规律的更多相关文章
- UVa 1620 Lazy Susan (找规律)
题意:给 n 个数,每次可以把4个连续的数字翻转,问你能不能形成1-n的环状排列. 析:找一下奇偶性,写几个数试试,就会找到规律. 代码如下: #include <cstdio> #inc ...
- UVA 10706 Number Sequence (找规律 + 打表 + 查找)
Problem B Number Sequence Input: standard input Output: standard output Time Limit: 1 second A singl ...
- Uva 11549 - Calculator Conundrum 找规律加map
题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- UVa 12627 (递归 计数 找规律) Erratic Expansion
直接说几个比较明显的规律吧. k个小时以后,红气球的个数为3k. 单独观察一行: 令f(r, k)为k个小时后第r行红气球的个数. 如果r为奇数,f(r, k) = f((r+1)/2, k-1) * ...
- UVA 11489 - Integer Game(找规律)
题目链接 #include <cstdio> #include <cstring> #include <string> #include <cmath> ...
- 【数论,找规律】Uva 11526 - H(n)
原来做过的题再看还是没想出来,看来当时必然没有真正理解.这次回顾感觉理解更透彻了. 网上的题解差不多都是一个版本,而且感觉有点扯.根据n=20猜出来的? 好吧哪能根据一个就猜到那么变态的公式.其实这题 ...
- uva 10706 Number Sequence(数学规律)
题目连接:10706 - Number Sequence 题目大意:有一个有0 ~ 9组成的序列,1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 ....就是第一位为1. ...
- 汉诺塔问题hdu 2065——找规律
这类题目就是纸上模拟,找规律. 问题描述:在一块铜板上有三根杆,目的是将最左边杆上的盘全部移到右边的杆上,条件是不允许直接从最左(右)边移到最右(左)边(每次移动一定是移到中间杆或从中间移出),也不允 ...
- hdu 2147 kiki's game 组合游戏 找规律
题目链接 题意 两人轮流将硬币从\((n,m)\)移动到\((1,1)\),每次只能向下或向左或向左下移动一格,最后无法移动者输.问先手会赢还是会输. 思路 找规律 -- P N P N P N P ...
随机推荐
- Intellij IDEA 最头大的问题,如何自定义注释模板?
想栈长我当初从 Eclipse 转用 IDEA 真是纠结,放弃然后尝试了N次,不过现在已经算是转型成功了,可以完全脱离 Eclipse 撸码了,虽然说我现在真的撸得非常少了.. 说到 IDEA 的痛点 ...
- Magento 中一个订单的“生命历程”
当我们在网上愉快的买买买的时候, 你知道在这些屏幕“背后”正在进行着什么吗? 1. 当一个产品被加入到购物车后, 实际上发生了什么? 当第一个产品被加入到购物车, 系统首先会生成一个 quote (q ...
- HDU4352 XHXJ's LIS(LIS 状压)
题意 题目链接 Sol 刚开始的思路是\(f[i][j]\)表示到第\(i\)位,LIS长度为\(j\)的方案. 然而发现根本不能转移,除非知道了之前的状态然后重新dp一遍.. 题解,,,挺暴力的把, ...
- Vue打包后页面出现cannot get
学习Vue有大半个月了,然而遇到了不少坑,完全没有高手们那么容易,中间有不少值得记录下的东东,回头好好理理.先理下今天的: Vue打包命令简单啊,直接在命令行输入:npm run build 然而没一 ...
- Mybatis介绍(一)
这里介绍的mybatis比较简单, 我做为一个初学者, 记录下个人在学习中方法, 如果那里出错, 希望读者朋友们见谅. 首先这里介绍一下我们下面用的表结构: author表是保存了作者的个人信息, 因 ...
- C# 获取当前文件、文件夹的路径及操作环境变量
一.获取当前文件的路径 1. System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName 获取模块的完整路径,包 ...
- Python __builtin__模块
你有没有好奇过当我们打开Python后就可以直接使用str(),list(),eval(),print(),max()这样的函数,而不用导入任何模块? 其实原因很简单,就是当我们打开Python解释器 ...
- JS encodeURIComponent函数
为了避免歧义,可以用JS 的encodeURIComponent函数 将有歧义的字符(?+=等)转换成对应的ASCII编码 for(var i=0;i<whichform.elements.l ...
- 运行自己的shell脚本
shell脚本可以直接./**.sh,也可以bash **.sh 我用./**.sh运行自己写的一个脚本,会出现如下的错误: bnrc@bnrc:~$ ./pixel.sh bash: ./pixel ...
- numpy.mean
http://docs.scipy.org/doc/numpy/reference/generated/numpy.mean.html numpy.mean(a, axis=None, dtype=N ...