B. Buggy Robot
来源:互联网 发布:mac下载office办公软件 编辑:程序博客网 时间:2024/06/05 16:21
Ivan has a robot which is situated on an infinite grid. Initially the robot is standing in the starting cell (0, 0). The robot can process commands. There are four types of commands it can perform:
- U — move from the cell (x, y) to (x, y + 1);
- D — move from (x, y) to (x, y - 1);
- L — move from (x, y) to (x - 1, y);
- R — move from (x, y) to (x + 1, y).
Ivan entered a sequence of n commands, and the robot processed it. After this sequence the robot ended up in the starting cell (0, 0), but Ivan doubts that the sequence is such that after performing it correctly the robot ends up in the same cell. He thinks that some commands were ignored by robot. To acknowledge whether the robot is severely bugged, he needs to calculate the maximum possible number of commands that were performed correctly. Help Ivan to do the calculations!
The first line contains one number n — the length of sequence of commands entered by Ivan (1 ≤ n ≤ 100).
The second line contains the sequence itself — a string consisting of n characters. Each character can be U, D, L or R.
Print the maximum possible number of commands from the sequence the robot could perform to end up in the starting cell.
4LDUR
4
5RRRUU
0
6LLRRRR
4
#include<stdio.h> #include<string.h> #include<algorithm> #include<math.h> #include<iostream> using namespace std; int n; int a[1005]; char c[100]; int min(int x,int y) { if(x<y) return x; else return y; } int main() { int n; while(~scanf("%d",&n)) { int sum=0; getchar(); for(int i=0;i<n;i++) { scanf("%c",&c[i]); } int l=0,r=0,u=0,d=0; for(int i=0;i<n;i++) { if(c[i]=='L') l++; else if(c[i]=='R') r++; else if(c[i]=='U') u++; else if(c[i]=='D') d++; } sum+=2*min(l,r); sum+=2*min(u,d); cout<<sum<<endl; } return 0; }
- B. Buggy Robot
- CodeForces 888B Buggy Robot
- codeforces 893B. Buggy Robot
- Codeforces 888B Buggy Robot (模拟)
- Educational Codeforces Round 32 B. Buggy Robot(模拟)
- Buggy Robot Gym
- Buggy Robot Gym
- Buggy Robot (二维压一维最短路
- UVA Live 7693 (Codeforces Gym 101201B) Buggy Robot DP+bfs
- B. Robot's Task
- Buggy Sorting
- Codeforces Round #323 B Robot's Task
- cf 583 B. Robot's Task(模拟)
- CodeForces 626A B - Robot Sequence
- Robot
- robot
- robot
- Robot
- C
- Ubuntu16.04安装Redis
- 【算法】Kruskal算法(解决最小生成树问题) 含代码实现
- A. Local Extrema
- Hbase原理、基本概念、基本架构
- B. Buggy Robot
- liunx lamp搭建编译
- Http请求中Content-Type讲解以及在Spring MVC中的应用
- Android SurfaceView入门学习
- Python机器学习numpy依赖包特征之间的相关性
- Geometry Problem HDU
- 利用Factory模式实现Fragment切换优化
- Android 引入Airbnb Lottie框架后,报错Error inflating class com.airbnb.lottie.LottieAnimationView
- 微信收红包自动化测试脚本