Grid(规律)
来源:互联网 发布:任务管理工具 知乎 编辑:程序博客网 时间:2024/06/05 11:14
Grid
时间限制: 1 Sec 内存限制: 128 MB提交: 318 解决: 40
[提交][状态][讨论版]
题目描述
Pong is wandering in the grids, and we take his initial position as (0,0). Each step he can move in the 4 directions of UP, DOWN, LEFT, RIGHT for one grid.
While we do know some of these steps, we are attacked by Pong’s birds (Pong have birds, maybe) so some steps remain unknown to us. Now we want to be informed how many possible ultimate position he might be.
While we do know some of these steps, we are attacked by Pong’s birds (Pong have birds, maybe) so some steps remain unknown to us. Now we want to be informed how many possible ultimate position he might be.
输入
For the first row there is an integer T(T ≤ 100), which is test cases.
For each case there are 2 rows. First row is an integer n(n ≤ 100000), next row is n operations consists of "UP","DOWN", "LEFT", "RIGHT", "?". Each operation is separated by a space.
For each case there are 2 rows. First row is an integer n(n ≤ 100000), next row is n operations consists of "UP","DOWN", "LEFT", "RIGHT", "?". Each operation is separated by a space.
输出
For each case you should output the answer.
样例输入
23UP ? LEFT4? UP ? RIGHT
样例输出
49
提示
因为上下左右确定的就知道终点了,然后就剩下“?”了,所以重点是?的个数,然后就找规律就好了
#include<bits/stdc++.h>using namespace std;#define maxn 1000#define maxm 100005#define rd(x) scanf("%d", &x)#define rd2(x, y) scanf("%d%d", &x, &y)long long int pk[100500];int main(){ int t, n; char s[1000000]; pk[1] = 1; pk[0] = 0; for(int i = 2; i <= 100005; i++) pk[i] = i*4 - 4 + pk[i-2]; rd(t); while(t--){ rd(n); int k = 0; getchar();///收回车 gets(s); ///不能收回车,但是遇到回车结束 int len = strlen(s); for(int i = 0; i < len; i++){ if(s[i] == '?') k++; } printf("%lld\n", pk[k+1]); } return 0;}
0 0
- Grid(规律)
- POJ 1942 Paths on a Grid 找规律+组合数学
- HDOJ1021(找规律)
- hdu 3184 (规律)
- hdu 1210 (规律)
- POJ1740(找规律)
- hdu (找规律)
- hdu4915(找规律)
- HDU5100(找规律)
- UVA - 11308(规律)
- HDU2053(打表找规律)
- HDU2700(规律)
- HDU2524(规律推导)
- Gridland ZOJ1037(规律)
- hdu1719-Friend(规律)
- Shopping(规律题)
- Hexagons!(找规律)
- Alarm(找规律)
- 访问虚拟机中web服务的方法
- 出现Access restriction: The type BASE64Encoder is not accessible 错误
- mysql处理字符串的两个绝招:substring_index,concat
- hive array基本操作:建表+查询+修改
- 【闭包概念】关于闭包概念各路神仙的不同解读——你可以自己理解。
- Grid(规律)
- Android开发:最全面、最易懂的Android屏幕适配解决方案
- linux编程基础:使用socketpair实现双向通讯
- Eclipse Maven建web项目 与SSM三大框架整合教程(Spring+SpringMVC+MyBatis)
- RecyclerView(ScrollView嵌套,添加HeardView、FootView)
- GitHub托管Android项目的多人开发
- Oracle解析复杂json的方法
- 剑指offer 33. 把数组排成最小的数
- javaSE_8系列博客——Java语言的特性(三)--类和对象(6)--为你的类提供构造函数