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. 面试题:Nginx负载均衡的算法怎么实现的?为什么要做动静分离?

    面试题 Nginx负载均衡的算法怎么实现的?Nginx 有哪些负载均衡策略?Nginx为什么要做动静分离? 面试官心理剖析 主要是看应聘人员对Nginx的基本原理是否熟悉,需要应聘人员能够根据实际业务 ...

  2. nginx的安装和负载均衡例子(RHEL/CentOS7.4)

    首先安装RHEL/CentOS7.4 mini ,然后关闭防火墙和 selinux ,更新系统(参看配置linux使用本地yum安装源和Redhat7/CentOS7 关闭防火墙和 selinux两个 ...

  3. https中引用http

    https里引用http不安全,会报错 解决方案 1.可以部署在http中,http中引用https不会存在安全问题报错 2.https中引用https,把需要引用的http部署成https

  4. 树的直径(BFS)

    ][];];];];,,;vis[i]=; ; j <= n ; j++){ ){;//标记 res[j]=res[root]+; ; i <= n- ; i++){; data[b][a ...

  5. Spring clound 微服务--理解篇

    定义:微服务就是一些协调工作的小而自治的服务 优点: 异构性:不同微服务可以使用不同的语言实现, 后端数据库也可以根据自身业务定义服务. 弹性: 一个组件不可用,不会导致级联故障.一个系统出了问题,不 ...

  6. js返回顶部小Demo

    <style> .divH { height: 1800px; } .divT { width: 50px; height: 50px; font-size: 18px; backgrou ...

  7. 11.Container With Most Water (Array; Two-Pointers)

    Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai).  ...

  8. Linux系统入门---开机启动流程

    目录 Linux系统入门---开机启动流程 一.centos6 二.systemd管理进程 1.查看级别 三.centos7实践案例: 1.案例1:centos7系统,单用户修改root密码 案例2: ...

  9. EnumPrinters

    https://blog.csdn.net/jilong17/article/details/6663734 已解决.开始hook的spoolss.dll里面的EnumPrinterW函数,应该hoo ...

  10. 力扣—gray code (格雷编码) python实现

    题目描述: 中文: 格雷编码是一个二进制数字系统,在该系统中,两个连续的数值仅有一个位数的差异. 给定一个代表编码总位数的非负整数 n,打印其格雷编码序列.格雷编码序列必须以 0 开头. 英文: Th ...