问题 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的更多相关文章

  1. Kattis - glitchbot 【DFS】

    Kattis - glitchbot [DFS] 题意 有一个机器人 刚开始在(0, 0),然后给出一个目标点,并且会给出一系列指令,但是其中会有一个指令是错误的.我们需要找出那个指令,并且改成正确的 ...

  2. upc组队赛6 GlitchBot【枚举】

    GlitchBot 题目描述 One of our delivery robots is malfunctioning! The job of the robot is simple; it shou ...

  3. GlitchBot -HZNU寒假集训

    One of our delivery robots is malfunctioning! The job of the robot is simple; it should follow a lis ...

随机推荐

  1. template.js artTemplate 简洁语法官网下载不了 template.js artTemplate 新下载地址

    参考:https://blog.csdn.net/tavatimsa/article/details/82019792

  2. css 获取从第n个开始,之后的所有元素

    <div id="box"> <div></div> <div>等待获取</div> <div>等待获取&l ...

  3. 一些关于SQL优化的总结

    由于这个项目一直都是mysql所以写点mysql的 1.数据存储引擎的选择,MyISAM 和 InnoDB 的选择 InnoDB 一般都会选择这个,但是如果真的涉及到一些不涉及增删的表,可以考虑下My ...

  4. WdatePicker日历添加事件,在任意月改变时处理日期事件

    原由 在做系统时根据要求有时候需要屏蔽掉某些特殊的日期,像周日或者法定假日,以及一些调班的日期:使用WdatePicker可以屏蔽掉周日和大多数法定假日,但像清明或者调班的日期则不好处理. 想法 1: ...

  5. HTML、CSS知识点,面试开发都会需要--No.7 数据列表

    No.7 数据列表 1.无序列表Unordered List 无序列表用block-level元素ul(unordered list)表示,每个item单独使用li(list)标记.如下代码所示: & ...

  6. linux--python虚拟环境篇

    python的虚拟环境 首先我们得知道为什么要要用虚拟环境? 在使用python开发过程中,各种业务需求多了,导致工程任务多了,难免会碰到不同的工程依赖不同版本库的问题,;或者是在开发的时候不想让物理 ...

  7. plupload多个实例,返回区分实例的返回

    plupload多个实例很简单,但是麻烦的是,返回的时候没有明显标记区分input的id,好蛋疼 var uploader = new plupload.Uploader({ //实例化一个plupl ...

  8. luogu3978 [TJOI2015]概率论

    题目链接:洛谷 题目大意:求所有$n$个点的有根二叉树的叶子节点数总和/$n$个点的有根二叉树的个数. 数据范围:$n\leq 10^9$ 生成函数神题!!!!(我只是来水博客的) 首先$n$个点的有 ...

  9. CentOS下rpm命令详解

    CentOS下rpm命令详解 rpm,Redhat Package Manager,即为红帽公司为RHEL开发的专用包管理器,后来更改为RPM Package Manager,类似于GNU项目,使用递 ...

  10. python基础(6)-深浅拷贝

    赋值 字符串和数字 # id()函数可以获取变量在内存中的地址标识 num1 = 2; num2 = 2; print(id(num1)) # result:8791124202560 print(i ...