upc组队赛6 GlitchBot【枚举】
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【枚举】的更多相关文章
- upc组队赛17 Bits Reverse【暴力枚举】
Bits Reverse 题目链接 题目描述 Now given two integers x and y, you can reverse every consecutive three bits ...
- upc组队赛12 Cardboard Container【枚举】
Cardboard Container Problem Description fidget spinners are so 2017; this years' rage are fidget cub ...
- upc组队赛6 Odd Gnome【枚举】
Odd Gnome 题目描述 According to the legend of Wizardry and Witchcraft, gnomes live in burrows undergroun ...
- upc组队赛5 Ground Defense【枚举】
Ground Defense 题目描述 You are a denizen of Linetopia, whose n major cities happen to be equally spaced ...
- upc组队赛2 Super-palindrome【暴力枚举】
Super-palindrome 题目描述 You are given a string that is consisted of lowercase English alphabet. You ar ...
- upc组队赛16 Melody【签到水】
Melody 题目描述 YellowStar is versatile. One day he writes a melody A = [A1, ..., AN ], and he has a sta ...
- upc组队赛6 Bumped!【最短路】
Bumped! 题目描述 Peter returned from the recently held ACM ICPC World finals only to find that his retur ...
- upc组队赛3 Chaarshanbegaan at Cafebazaar
Chaarshanbegaan at Cafebazaar 题目链接 http://icpc.upc.edu.cn/problem.php?cid=1618&pid=1 题目描述 Chaars ...
- upc组队赛1 过分的谜题【找规律】
过分的谜题 题目描述 2060年是云南中医学院的百年校庆,于是学生会的同学们搞了一个连续猜谜活动:共有10个谜题,现在告诉所有人第一个谜题,每个谜题的答案就是下一个谜题的线索....成功破解最后一个谜 ...
随机推荐
- 第一步:卸载手机上的“WIFI万能钥匙”! 会分享自己家的wifi
http://www.znds.com/tv-164866-1-1.html 楼主今日家中WIFI卡的不行,心想,20M的电信光纤没理由这么卡!于是就在网上查找了许多资料,接下来统一收集整理给大家!第 ...
- PAT甲级【2019年3月考题】——A1157 Anniversary【25】
Zhejiang University is about to celebrate her 122th anniversary in 2019. To prepare for the celebrat ...
- 基于全局地址池的DHCP
一.实验目的 二.实验拓扑图 .三.实验编址 四.实验步骤 1.配置IP 2.配置基于全局地址池的DHCP server 使用IP pool命令创建一个新的全局地址池,名称为hjt1 配置hjt1可动 ...
- QTP 通过URL地址下载文件到本地(转)
While automation, you may come to situations where you need to need to download a file on clicking a ...
- 常用缓存淘汰算法(LFU、LRU、ARC、FIFO、MRU)
缓存算法是指令的一个明细表,用于决定缓存系统中哪些数据应该被删去. 常见类型包括LFU.LRU.ARC.FIFO.MRU. 最不经常使用算法(LFU): 这个缓存算法使用一个计数器来记录条目被访问的频 ...
- gulp构建前端,压缩css,js文件,实现浏览器自动刷新
一.安装node nodejs下载地址:https://nodejs.org/ nodejs自带npm模块管理器,安装完成之后打开dos命令窗口输入 node -v就能查看nodejs是否安装成成功 ...
- 【知识强化】第四章 网络层 4.8 移动IP
这节课我们来学习一下移动IP. 那移动IP呢要跟动态IP区分开.动态IP是指,通过使用DHCP协议,在一个局域网内部的一台主机,就可以动态地获得一个IP地址.那这里面的移动IP是什么意思呢? 我们来举 ...
- Pandas_key_point
10分钟快速入门pandas: http://pandas.pydata.org/pandas-docs/stable/10min.html ----------------------------- ...
- H5 移动调试全攻略
H5 移动调试全攻略 随着移动设备的高速发展,H5 开发也成为了 F2E 不可或缺的能力.而移动开发的重中之重就是掌握调试技巧,定 Bug于无形. 一.概要 因为移动端操作系统分为 iOS 和 And ...
- 3、selenium 问题汇总
一.'chromedriver' executable needs to be in PAT: 解决方法 下载谷歌驱动文件:Chromedriver.exe 将Chromedriver.exe 拷贝 ...