GlitchBot

题目描述

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;
}

upc组队赛6 GlitchBot【枚举】的更多相关文章

  1. upc组队赛17 Bits Reverse【暴力枚举】

    Bits Reverse 题目链接 题目描述 Now given two integers x and y, you can reverse every consecutive three bits ...

  2. upc组队赛12 Cardboard Container【枚举】

    Cardboard Container Problem Description fidget spinners are so 2017; this years' rage are fidget cub ...

  3. upc组队赛6 Odd Gnome【枚举】

    Odd Gnome 题目描述 According to the legend of Wizardry and Witchcraft, gnomes live in burrows undergroun ...

  4. upc组队赛5 Ground Defense【枚举】

    Ground Defense 题目描述 You are a denizen of Linetopia, whose n major cities happen to be equally spaced ...

  5. upc组队赛2 Super-palindrome【暴力枚举】

    Super-palindrome 题目描述 You are given a string that is consisted of lowercase English alphabet. You ar ...

  6. upc组队赛16 Melody【签到水】

    Melody 题目描述 YellowStar is versatile. One day he writes a melody A = [A1, ..., AN ], and he has a sta ...

  7. upc组队赛6 Bumped!【最短路】

    Bumped! 题目描述 Peter returned from the recently held ACM ICPC World finals only to find that his retur ...

  8. upc组队赛3 Chaarshanbegaan at Cafebazaar

    Chaarshanbegaan at Cafebazaar 题目链接 http://icpc.upc.edu.cn/problem.php?cid=1618&pid=1 题目描述 Chaars ...

  9. upc组队赛1 过分的谜题【找规律】

    过分的谜题 题目描述 2060年是云南中医学院的百年校庆,于是学生会的同学们搞了一个连续猜谜活动:共有10个谜题,现在告诉所有人第一个谜题,每个谜题的答案就是下一个谜题的线索....成功破解最后一个谜 ...

随机推荐

  1. [题解]RGB Substring (hard version)-前缀和(codeforces 1196D2)

    题目链接:https://codeforces.com/problemset/problem/1196/D2 题意: q 个询问,每个查询将给你一个由 n 个字符组成的字符串s,每个字符都是 “R”. ...

  2. div中的div上下居中

    方法1: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 .parent {           width:800px;           height:500px;       ...

  3. 常用缓存淘汰算法(LFU、LRU、ARC、FIFO、MRU)

    缓存算法是指令的一个明细表,用于决定缓存系统中哪些数据应该被删去. 常见类型包括LFU.LRU.ARC.FIFO.MRU. 最不经常使用算法(LFU): 这个缓存算法使用一个计数器来记录条目被访问的频 ...

  4. 轻松上手nodeJs爬取想要页面的数据

    开始之前请先确保自己安装了Node.js环境!!!!!!!! 1.在项目文件夹安装两个必须的依赖包 npm install superagent -S SuperAgent(官网是这样解释的) --- ...

  5. LeetCode Array Easy 268. Missing Number

    Description Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one th ...

  6. spring 事物(二)—— 编程式事物实现与扩展

    简介 使用TransactionTemplate 不需要显式地开始事务,甚至不需要显式地提交事务.这些步骤都由模板完成.但出现异常时,应通过TransactionStatus 的setRollback ...

  7. 从Linux传输apk包到Windows系统,一周的心路历程,累

    1.在Windows服务器上打开一个cmd窗口,执行脚本,只适用于Windows系统 --NO String cmd = "cmd.exe /c adb -s f223413 install ...

  8. pycharm配色

    setting-appearanse-theme-IntelliJ setting-Editer-color scheme-Default setting-Editer-color scheme-py ...

  9. Charles IOS https抓包

    步骤 1.下载charles: https://www.charlesproxy.com/download/ 只有一个30天试用版,每次打开只能30分钟,如果想时间长点,就找破解版或者买个licenc ...

  10. C++11新特性之 Move semantics(移动语义)

    https://blog.csdn.net/wangshubo1989/article/details/49748703 这篇讲到了vector的push_back的两种重载版本,左值版本和右值版本.