[ACM_模拟] UVA 12503 Robot Instructions [指令控制坐标轴上机器人移动 水]

简介:


 

 

  Robot Instructions 

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.

 

Input 

The first line contains the number of test cases T (   T$ \le$100). Each test case begins with an integer n (   1$ \le$n$ \le$100), the number of instructions. Each of the following n lines contains an instruction.   

 

Output 

For each test case, print the final position of the robot. Note that after processing each test case, the robot should be reset to the origin.   

 

Sample Input 

 

2
3
LEFT
RIGHT
SAME AS 2
5
LEFT
SAME AS 1
SAME AS 2
SAME AS 1
SAME AS 4

 

Sample Output 

 

1
-5


题目大意:机器人在原点,有3种命令:LEFT坐标减1,RIGHT坐标加1,SAME AS n和第n个命令一样,问最后机器人的坐标。水题不解释!
复制代码
 1 #include<iostream>
 2 #include<cstdio>
 3 #include<string>
 4 #include<string.h>
 5 #include<cstring>
 6 #include<sstream>
 7 using namespace std;
 8 int main(){
 9     string str;
10     int T;cin>>T;
11     getline(cin,str);
12     while(T--){
13         int n;cin>>n;
14         getline(cin,str);
15         int move[105];
16         int sum=0;
17         for(int i=1;i<=n;i++){
18             getline(cin,str);
19             if(str[0]=='L')move[i]=-1;
20             else if(str[0]=='R')move[i]=1;
21             else{
22                 string temp=str.substr(8);
23                 istringstream in(temp);
24                 int t;
25                 in>>t;
26                 move[i]=move[t];
27             }
28             sum+=move[i];
29         }
30         cout<<sum<<'\n';
31     }return 0;
32 }
复制代码
相关文章
|
传感器 机器学习/深度学习 Web App开发
AI之Robot:机器人Robot的简介、发展历史、案例应用之详细攻略
AI之Robot:机器人Robot的简介、发展历史、案例应用之详细攻略
|
6月前
|
自然语言处理 机器人 API
Instruct2Act:使用大型语言模型将多模态指令映射到机器人动作
Instruct2Act是一个框架,它结合了大型语言模型和多模态基础模型,将自然语言和视觉指令转换为机器人的顺序动作,实现精确的感知、规划和行动,展示了强大的零样本性能和灵活性。
99 0
Instruct2Act:使用大型语言模型将多模态指令映射到机器人动作
|
8月前
|
机器学习/深度学习 传感器 算法
强化学习(RL)在机器人领域的应用,尤其是结合ROS(Robot Operating System)和Gazebo(机器人仿真环境)
强化学习(RL)在机器人领域的应用,尤其是结合ROS(Robot Operating System)和Gazebo(机器人仿真环境)
356 2
|
传感器 XML 数据可视化
[ros robot] --- 机器人系统仿真
[ros robot] --- 机器人系统仿真
409 0
|
机器人 语音技术 Android开发
App Inventor 2 语音交互机器人Robot,使用讯飞语音识别引擎
App Inventor 2 语音识别及交互App。识别语言指令并控制机器人运动,主要用到语音识别器及文本朗读器组件,语音识别相关开发最佳入门。代码逻辑简单,App交互性及趣味性非常强~
276 0
|
机器学习/深度学习 自然语言处理 算法
轻松完成700多条指令、成功率达97%!谷歌开源机器人领域transformer
轻松完成700多条指令、成功率达97%!谷歌开源机器人领域transformer
205 0
|
自然语言处理 数据可视化 机器人
《机器人编程实战》一一1.2 给机器人指令
本节书摘来自华章出版社《机器人编程实战》一 书中的第1章,第1.2节,作者:[美]卡梅伦·休斯(Cameron Hughes) 特雷西·休斯(Tracey Hughes)著 ,更多章节内容可以访问云栖社区“华章计算机”公众号查看。
1478 0

热门文章

最新文章