问题 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. poj 3348

    裸的凸包,,我就来粘一下板子 把jls和dls的代码混合了一下(雾),感觉我要是能把camp里的几何掌握的差不多就稳         了.(mxy到底打了什么?) 感觉叉积实在是个好东西qwq 今晚c ...

  2. Gym 101810

    友情提示: 这篇题解并没有GJKL,因为我也不会,而且看别人代码也看不懂,而且问学长还不给我讲!hmc:这个题巨麻烦,我只能说balabala.我不学了我退役了啊! A:这傻逼题我从开头wa了四个小时 ...

  3. 【C++类与对象】实验四(二)

    实现画图类 #ifndef GRAPH_H #define GRAPH_H // 类Graph的声明 class Graph { public: Graph(char ch, int n); // 带 ...

  4. CSS斜切角

    问题 斜切角在Web设计和印刷中是相当受欢迎的样式.它通常是在一个或多个元素的角落切一个45°的角(也就是所谓的斜切角).特别是最近,扁平化设计的势头压过了拟真设计,也使这种效果更加流行.当斜切角只存 ...

  5. jquery chrome中取select 的值一就返回了

    在 <div class="controls"> <select class="span2" data-val="true" ...

  6. [redis] redis cli的学习记录

    文档: https://redis.io/topics/rediscli help命令: The command can be used in two forms: . help @<categ ...

  7. Cocoa 框架 For iOS(一) 框架的介绍,Objectivie-C运行时能力的解析等 (转载)

    http://blog.csdn.net/totogo2010/article/details/8081253 Cocoa框架是iOS应用程序的基础,了解Cocoa框架,对开发iOS应用有很大的帮助. ...

  8. javascript常用的操作

    1.concat()  连接两个或更多的数组,并返回一个新的数组.注意:该方法不会改变原数组 var arry1=["李四",“王二”]:  var arry2=['赵柳',“李旺 ...

  9. 小程序 切换到tabBar页面不刷新问题

    小程序跳转的几种方式有wx.navigateTo,wx.redirectTo,wx.reLaunch,wx.switchTab等.下面我们重点研究切换到tabBar的两种方式. wx.switchTa ...

  10. linux系统644、755、777权限详解

    在linux系统中644.755.777三种权限是非常重要的一些权限了,下面我来详细的介绍644.755.777三种权限的使用,希望对各位有帮助. 常用的linux文件权限:444 r--r--r-- ...