Robot Instructions UVA
来源:互联网 发布:新业汽修软件注册码 编辑:程序博客网 时间:2024/06/05 14:52
Robot Instructions UVA - 12503
题目传送门
:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3947
You have a robot standing on the origin of x axis. The robot will be given some instructions. Your
task is to predict its position after executing all the instructions.
• LEFT: move one unit left (decrease p by 1, where p is the position of the robot before moving)
• RIGHT: move one unit right (increase p by 1)
• SAME AS i: perform the same action as in the i-th instruction. It is guaranteed that i is a positive
integer not greater than the number of instructions before this.
题目大意:做操作,左减右加,重复的操作用same as 来代替;
水;
AC Code:以下代码看不懂set函数的,可以去参考:
http://blog.csdn.net/qq_36525906/article/details/72356136
#include <iostream>#include <bits/stdc++.h>using namespace std;int sum = 0;char s[100];int i = 1;set<int>m1,m2;int same(int l){ if(m1.find(l) != m1.end()) { sum--; m1.insert(i); } else if(m2.find(l) != m2.end()) { sum++; m2.insert(i); } return 0;}int main(){ int t; cin>>t; while(t--) { memset(s,0,sizeof(s)); int n; cin>>n; sum = 0; i=1; while(n--) { scanf("%s",s); if(strcmp(s,"LEFT") == 0) { sum--; m1.insert(i); } else if(strcmp(s,"RIGHT") == 0) { sum++; m2.insert(i); } else { int k; char ss[100]; scanf("%s %d",ss,&k); same(k); } i++; } cout<<sum<<endl; m1.clear(); m2.clear(); } return 0;}
- UVA 12503 - Robot Instructions
- UVa 12503 - Robot Instructions
- Robot Instructions UVA
- Robot Instructions
- Robot Instructions
- 12503 - Robot Instructions
- UVA12503-Robot Instructions
- UVA 10116 - Robot Motion
- 【uva】1600 - Patrol Robot
- UVa 10116 - Robot Motion
- UVa 1600 - Patrol Robot
- UVA 1600 Patrol Robot
- UVa 1600 Patrol Robot
- UVA 1600 Patrol Robot
- Uva - 1600 - Patrol Robot
- UVa - 1622 - Robot
- uva 1600 Patrol Robot
- UVa 314 - Robot (bfs)
- NPM express模块本地安装和全局安装详解
- net.sf.json.JSONException: Object is null
- JMeter之Ramp-up Period(in seconds)说明(可同时并发)
- 初学python+selenium之路2:窗口简单的定位
- 【笨鸟先飞】android重新学习日记6---使用intent的组件(广播Broadcast)
- Robot Instructions UVA
- 【笨鸟先飞】android重新学习日记7---传递数据的方法(contentProvider)
- 行内标签a,span等调整高宽的方案
- grid中显示blobImage上传的图片 通过本案例,我们实现blobImage上传的图片在grid表格中的显示。 grid的cellRender方法渲染单元格显示图片,例: 1 2 3 4 5
- 【转载】diff详细用法
- React+webpack 的开发环境配置步骤(四)
- leetcode --15. 3Sum
- <<opencv>>入门关于启动摄像头阈值化
- arcgis android开发之添加地图控件并缩放至当前位置