GlitchBot
问题 F: GlitchBot
时间限制: 1 Sec 内存限制: 128 MB
提交: 230 解决: 113
[提交] [状态] [命题人:admin]
题目描述
One of our delivery robots is malfunctioning! The job of the robot is simple; it should follow a list of instructions in order to reach a target destination. The list of instructions is originally correct to get the robot to the target. However, something is going wrong as we upload the instructions into the robot’s memory. During the upload, one random instruction from the list takes on a different value than intended. Yes,there is always a single bad instruction in the robot’s memory and it always results in the robot arriving at an incorrect destination as it finishes executing the list of instructions.
The robot can execute the instructions “Left”, “Right”, and “Forward”. The “Left” and “Right” instructions do not result in spatial movement but result in a 90-degree turn in the corresponding direction. “Forward” is the only instruction that results in spatial movement, causing the robot to move one unit in the direction it is facing. The robot always starts at the origin (0, 0) of a grid and faces north along the positive y-axis.
Given the coordinates of the target destination and the list of instructions that the robot has in its memory, you are to identify a correction to the instructions to help the robot reach the proper destination.
输入
The first line of the input contains the x and y integer coordinates of the target destination, where −50 ≤ x ≤ 50 and −50 ≤ y ≤ 50. The following line contains an integer n representing the number of instructions in the list, where 1 ≤ n ≤ 50. The remaining n lines each contain a single instruction. These instructions may be: “Left”, “Forward”, or “Right”.
输出
Identify how to correct the robot’s instructions by printing the line number (starting at 1) of an incorrect input instruction, followed by an instruction substitution that would make the robot reach the target destination. If there are multiple ways to fix the instructions, report the fix that occurs for the earliest line number in the sequence of instructions. There is always exactly one unique earliest fix.
样例输入
3 2
11
Forward
Right
Forward
Forward
Left
Forward
Forward
Left
Forward
Right
Forward
样例输出
8 Right
题意:有个机器人 Forward 向前走 Left向左转向 Right向右转向
从(0,0)走到(xx,yy) n步操作,有一步操作是错的,要把他修改成其他操作到达(xx,yy)
枚举每一个操作,将其改成其他两种操作,看能不能到达终点
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define rep(i,a,n) for(int i=a;i<n;++i)
#define readc(x) scanf("%c",&x)
#define read(x) scanf("%d",&x)
#define sca(x) scanf("%d",&x)
#define sca2(x,y) scanf("%d%d",&x,&y)
#define sca3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define print(x) printf("%d\n",x)
#define mst(a,b) memset(a,b,sizeof(a))
#define lowbit(x) x&-x
#define lson(x) x<<1
#define rson(x) x<<1|1
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> P;
const int INF =0x3f3f3f3f;
const int inf =0x3f3f3f3f;
const int mod = 1e9+7;
const int MAXN = 105;
const int maxn =1000010;
using namespace std;
int xx,yy;
int m;
string s[55];
string f[3] = {"Forward","Left","Right"};
int dir[4][2] = {0,1,-1,0,0,-1,1,0}; //0上1左2下3右 left
int x = 0,y = 0;
bool solve(string s[]){
x = y = 0;
int ori = 0;
for(int i = 0 ;i < m; i++){
if(s[i] == f[0]){
x += dir[ori][0];
y += dir[ori][1];
}
else if(s[i] == f[1])
ori = (ori + 1) % 4;
else
ori = (ori + 4 - 1) % 4;
}
return xx == x && yy == y;
}
int main(){
ios::sync_with_stdio(false);
cin >> xx >> yy >> m;
for(int i = 0; i < m; i++)
cin >> s[i];
for(int i = 0; i < m; i++){
string tmp = s[i];
for(int j = 0; j < 3; j++){
if(s[i] == f[j]){
for(int k = 0; k < 3; k++){
if(j == k) continue;
s[i] = f[k];
if(solve(s)){
cout << i + 1 << " " << s[i]<< endl;
return 0;
}
s[i] = tmp;
}
}
}
}
return 0;
}
GlitchBot的更多相关文章
- Kattis - glitchbot 【DFS】
Kattis - glitchbot [DFS] 题意 有一个机器人 刚开始在(0, 0),然后给出一个目标点,并且会给出一系列指令,但是其中会有一个指令是错误的.我们需要找出那个指令,并且改成正确的 ...
- upc组队赛6 GlitchBot【枚举】
GlitchBot 题目描述 One of our delivery robots is malfunctioning! The job of the robot is simple; it shou ...
- GlitchBot -HZNU寒假集训
One of our delivery robots is malfunctioning! The job of the robot is simple; it should follow a lis ...
随机推荐
- re:从零开始的数位dp
起源:唔,,前几天打cf,edu50那场被C题虐了,决定学学数位dp.(此文持续更新至9.19) ps:我也什么都不会遇到一些胡话大家不要喷我啊... 数位dp问题:就是求在区间l到r上满足规定条件的 ...
- mysql 查询排名 返回值拼接的骚操作
故事背景: 依照原系统的框子搞一个新的系统给其他人使用,因为新的系统配置库依然需要使用原有的表,表中有字段区分新的系统,然后就有了这个很没劲的数据同步. 难点:配置库码表数据的主键之前是自增,后来改造 ...
- vue前后分离---数据模拟
最近为在做CRM的前期工作,忙里偷闲写了个关于数据模拟方面的东西 主要是现在博客中满天都再说前后分离,但是还没有几个实际操作的---让许多新手{-_-} 方法一: 启动一个express静态服务器-- ...
- javascript的数组之find()
find()方法返回数组中第一个满足回调函数测试的第一个元素的值.否则返回undefined const arr1 = [1, 2, 3, 4, 6, 9]; let found = arr1.fin ...
- python全栈开发 * 10知识点汇总 * 180612
10 函数进阶 知识点汇总 一.动态参数 形参的第三种1.动态接收位置传参 表达:*args (在参数位置编写 * 表⽰接收任意内容) (1)动态位置参数def eat(*args): print(a ...
- AutoBat
var currentDir = Directory.GetCurrentDirectory(); var filePath = string.Format("{0}\\Auto.bat&q ...
- 阻塞队列(BlockingQueue)
阻塞队列是 java.util.concurrent 包提供的一个类,该类提供了多线程中通过队列实现安全高效的数据处理的功能. 所谓阻塞队列,是在普通队列基础上实现了阻塞线程的功能: 队列为空时,获取 ...
- python框架之Django(4)-视图&路由
视图 负责接收请求和返回响应 FBV和CBV FBV FBV(function base views) 就是在视图里使用函数处理请求. from django.conf.urls import url ...
- python框架之Django(15)-contenttype模块
假如有一个书城系统,需要给作者和书籍加上评论功能.如果给每个表单独建一个评论表,那么我们以后要扩展其它模块评论功能的时候,还需要随之新建一张评论表,会显得很冗余.对于这种情况,Django 给我们提供 ...
- 经典的PHPer为什么被认为是草根?
PHPer是草根吗? 从PHP诞生之日起,PHP就开始在Web应用方面为广大的程序员服务.同时,作为针对Web开发量身定制的脚本语言,PHP一直秉承简单.开源的思想,这也使得PHP得以快速的发展,并且 ...