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. drf 分页,获取fk,choise,m2m等字段数据(序列化)

    1.什么是restful规范 是一套规则,用于程序之间进行数据交换的约定. 他规定了一些协议,对我们感受最直接的的是,以前写增删改查需要写4个接口,restful规范的就是1个接口,根据method的 ...

  2. taintCheck的实现

    参考:http://bitblaze.cs.berkeley.edu/papers/taintcheck-full.pdf 1. 应用taint analysis需要解决三个问题 a. 哪些input ...

  3. docker 提示 Drive has not been shared 错误

    Creating laradock_docker-in-docker_1 ... Creating laradock_docker-in-docker_1 ... error ERROR: for l ...

  4. checkBox的全选与全不选

    //初始加载 $(function () {   LoadCart(); }); var RMB = 0; var Index = 0; var shu = 0; var ResultStr = &q ...

  5. 深入理解__proto__ 、constructor和prototype的关系

    深入理解__proto__ .constructor和prototype的关系 2013-11-12 09:56 1390人阅读 评论(3) 收藏 举报  分类: 前端之Javascript(59)  ...

  6. luoguP1083 借教室(题解)(我用的线段树)

    luoguP1083 借教室 题目 #include<cstdio> #include<iostream> #include<cmath> #include< ...

  7. redis-3.0.0安装

    redis-3.0.0安装 前言 redis是常用的no-sql数据库,常用于缓存数据,同时,他也可以持久化数据.他是C语言开发的,所以安装的时候需要编译. 单机版redis yum install ...

  8. PHP 接口签名验证

    目录 概览 常用验证 单向散列加密 对称加密 非对称加密 密钥安全管理 接口调试工具 在线接口文档 扩展 小结 概览 工作中,我们时刻都会和接口打交道,有的是调取他人的接口,有的是为他人提供接口,在这 ...

  9. sqlacodegen:通过mysql语句生成sqlalchemy的model

    引用网页描述:这个工具读取现有数据库的结构并生成相应的SQLAlchemy模型代码. 使用方法详细描述在如下连接中. 先简要介绍使用方法: 安装:pip install  sqlacodegen sq ...

  10. [几何]计算不规则多边形的面积、中心、重心(Android,转)

    转自:[几何]计算不规则多边形的面积.中心.重心 最近项目用到:在不规则多边形的中心点加一个图标.(e.g: xx地区发生暴雪,暴雪区域是多边形,给多边形中心加一个暴雪的图标) 之前的设计是,计算不规 ...