Codeforces 752C Santa Claus and Robot 思维
2016-12-25 21:24
363 查看
点击打开链接
题意:给出路线,要求在上面放p个点(p尽量小&&pi,pi+1之间为最短路径)
思路 若s[i]和s[j]为pk和pk+1,因为pk->pk+1是最短路径 所以s[i]->s[j]的路径是递增的,(即路径是:曼哈顿距离) 找到最长递增序列的个数即可
题意:给出路线,要求在上面放p个点(p尽量小&&pi,pi+1之间为最短路径)
思路 若s[i]和s[j]为pk和pk+1,因为pk->pk+1是最短路径 所以s[i]->s[j]的路径是递增的,(即路径是:曼哈顿距离) 找到最长递增序列的个数即可
#include <iostream> using namespace std; int n, Left, Right, Down, Up, sum = 1; string s; int main() { cin >> n >> s; for(int i = 0 ; i < n ; i++){ if(s[i] == 'U' && Down){ sum++; Down = Right = Left = Up = 0; } if(s[i] == 'D' && Up){ sum++; Down = Right = Left = Up = 0; } if(s[i] == 'L' && Right){ sum++; Down = Right = Left = Up = 0; } if(s[i] == 'R' && Left){ sum++; Down = Right = Left = Up = 0; } if(s[i] == 'U') Up++; if(s[i] == 'D') Down++; if(s[i] == 'R') Right++; if(s[i] == 'L') Left++; } cout << sum << endl; return 0; }
相关文章推荐
- 【Codeforces 748 C Santa Claus and Robot】+ 思维
- 【Codeforces Round #389】Codeforces 752C Santa Claus and Robot
- CodeForces - 748C Santa Claus and Robot(思维)
- 【codeforces 752C】Santa Claus and Robot
- CodeForces 748C Santa Claus and Robot (思维)
- 【codeforces 752C】Santa Claus and Robot
- 【codeforces 752C】Santa Claus and Robot
- 【codeforces 752C】Santa Claus and Robot
- Codeforces Round #389(Div.2)C Santa Claus and Robot【思维】
- CodeForces 748E. Santa Claus and Tangerines(二分,递推)
- 模拟· CodeForces - 748B · Santa Claus and Keyboard Check
- Codeforces 748B-Santa Claus and Keyboard Check
- 【Codeforces Round #389】Codeforces 752E Santa Claus and Tangerines【解法一】
- Codeforces 752E Santa Claus and Tangerines 二分+记忆化
- Codeforces 748E - Santa Claus and Tangerines
- 【Codeforces 748 B Santa Claus and Keyboard Check】
- CodeForces 748E. Santa Claus and Tangerines 题解(递推or二分)
- 748C Santa Claus and Robot
- CodeForces - 748E Santa Claus and Tangerines(枚举)
- C. Santa Claus and Robot 思考题