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 9090-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)(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.

Input

The first line of the input contains the xx and yy integer coordinates of the target destination, where −50≤x≤50−50≤x≤50 and −50≤y≤50−50≤y≤50. The following line contains an integer nn representing the number of instructions in the list, where 1≤n≤501≤n≤50. The remaining nn lines each contain a single instruction. These instructions may be: “Left”, “Forward”, or “Right”.

Output

Identify how to correct the robot’s instructions by printing the line number (starting at 11) 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.

Sample Input 1 Sample Output 1
3 2
11
Forward
Right
Forward
Forward
Left
Forward
Forward
Left
Forward
Right
Forward
8 Right
Sample Input 2 Sample Output 2
-1 1
3
Right
Left
Forward
1 Forward

题解:给一个指定的点,给机器人下指令,前进、向右或者向左转,然后机器人出了故障,中间有一个命令出错了(可能有多种解决方案,输出最早的),找到第几个出错,并输出正确指令。

 #include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
int x, y;
int n;
char ins[][];
int map[][] = {};
int go[][] = { {,},{,},{-,},{,-} };
int main()
{
int turn = ;
scanf("%d %d", &x, &y);
scanf("%d", &n);
for (int i = ; i <= n; i++)
{
scanf("%s", ins[i]);
}
for (int i = ; i <= n; i++)
{
if (strcmp(ins[i], "Forward") == )
{
strcpy(ins[i],"Right");
turn = ;
for (int j = ; j <= n; j++)
{
if (strcmp(ins[j], "Forward") == )
{
map[][] += go[turn][]; //y
map[][] += go[turn][]; //x
}
else if (strcmp(ins[j], "Right") == )
{
turn++;
if (turn > ) turn = ;
}
else
{
turn--;
if (turn < ) turn = ;
}
}
if (map[][] == y&&map[][] == x)
{
printf("%d %s\n", i, ins[i]);
break;
}
map[][] = ;
map[][] = ;
strcpy(ins[i], "Left");
turn = ;
for (int j = ; j <= n; j++)
{
if (strcmp(ins[j], "Forward") == )
{
map[][] += go[turn][]; //y
map[][] += go[turn][]; //x
}
else if (strcmp(ins[j], "Right") == )
{
turn++;
if (turn > ) turn = ;
}
else
{
turn--;
if (turn < ) turn = ;
}
}
if (map[][] == y&&map[][] == x)
{
printf("%d %s\n", i, ins[i]);
break;
}
strcpy(ins[i], "Forward");
map[][] = ;
map[][] = ;
}
else if (strcmp(ins[i], "Right") == )
{ strcpy(ins[i], "Forward");
turn = ;
for (int j = ; j <= n; j++)
{
if (strcmp(ins[j], "Forward") == )
{
map[][] += go[turn][]; //y
map[][] += go[turn][]; //x
}
else if (strcmp(ins[j], "Right") == )
{
turn++;
if (turn > ) turn = ;
}
else
{
turn--;
if (turn < ) turn = ;
}
}
if (map[][] == y&&map[][] == x)
{
printf("%d %s\n", i, ins[i]);
break;
}
map[][] = ;
map[][] = ;
strcpy(ins[i], "Left");
turn = ;
for (int j = ; j <= n; j++)
{
if (strcmp(ins[j], "Forward") == )
{
map[][] += go[turn][]; //y
map[][] += go[turn][]; //x
}
else if (strcmp(ins[j], "Right") == )
{
turn++;
if (turn > ) turn = ;
}
else
{
turn--;
if (turn < ) turn = ;
}
}
if (map[][] == y&&map[][] == x)
{
printf("%d %s\n", i, ins[i]);
break;
}
strcpy(ins[i], "Right");
map[][] = ;
map[][] = ;
}
else
{ strcpy(ins[i], "Right");
turn = ;
for (int j = ; j <= n; j++)
{
if (strcmp(ins[j], "Forward") == )
{
map[][] += go[turn][]; //y
map[][] += go[turn][]; //x
}
else if (strcmp(ins[j], "Right") == )
{
turn++;
if (turn > ) turn = ;
}
else
{
turn--;
if (turn < ) turn = ;
}
}
if (map[][] == y&&map[][] == x)
{
printf("%d %s\n", i, ins[i]);
break;
}
map[][] = ;
map[][] = ;
strcpy(ins[i], "Forward");
turn = ;
for (int j = ; j <= n; j++)
{
if (strcmp(ins[j], "Forward") == )
{
map[][] += go[turn][]; //y
map[][] += go[turn][]; //x
}
else if (strcmp(ins[j], "Right") == )
{
turn++;
if (turn > ) turn = ;
}
else
{
turn--;
if (turn < ) turn = ;
}
}
if (map[][] == y&&map[][] == x)
{
printf("%d %s\n", i, ins[i]);
break;
}
strcpy(ins[i], "Left");
map[][] = ;
map[][] = ;
} }
return ;
}

GlitchBot -HZNU寒假集训的更多相关文章

  1. Wooden Sticks -HZNU寒假集训

    Wooden Sticks There is a pile of n wooden sticks. The length and weight of each stick are known in a ...

  2. 今年暑假不AC - HZNU寒假集训

    今年暑假不AC "今年暑假不AC?" "是的." "那你干什么呢?" "看世界杯呀,笨蛋!" "@#$%^&a ...

  3. FatMouse' Trade -HZNU寒假集训

    FatMouse' Trade FatMouse prepared M pounds of cat food, ready to trade with the cats guarding the wa ...

  4. 畅通工程-HZNU寒假集训

    畅通工程 某省调查城镇交通状况,得到现有城镇道路统计表,表中列出了每条道路直接连通的城镇.省政府"畅通工程"的目标是使全省任何两个城镇间都可以实现交通(但不一定有直接的道路相连,只 ...

  5. 并查集模板题(The Suspects )HZNU寒假集训

    The Suspects Time Limit: 1000MS Memory Limit: 20000KTotal Submissions: 36817 Accepted: 17860 Descrip ...

  6. CSU-ACM寒假集训选拔-入门题

    CSU-ACM寒假集训选拔-入门题 仅选择部分有价值的题 J(2165): 时间旅行 Description 假设 Bobo 位于时间轴(数轴)上 t0 点,他要使用时间机器回到区间 (0, h] 中 ...

  7. 中南大学2019年ACM寒假集训前期训练题集(基础题)

    先写一部分,持续到更新完. A: 寒衣调 Description 男从戎,女守家.一夜,狼烟四起,男战死沙场.从此一道黄泉,两地离别.最后,女终于在等待中老去逝去.逝去的最后是换尽一生等到的相逢和团圆 ...

  8. 2022寒假集训day2

    day1:学习seach和回溯,初步了解. day2:深度优化搜索 T1 洛谷P157:https://www.luogu.com.cn/problem/P1157 题目描述 排列与组合是常用的数学方 ...

  9. 食物链-HZUN寒假集训

    食物链 总时间限制: 1000ms 内存限制: 65536kB 描述 动物王国中有三类动物A,B,C,这三类动物的食物链构成了有趣的环形.A吃B, B吃C,C吃A. 现有N个动物,以1-N编号.每个动 ...

随机推荐

  1. 【一天一道LeetCode】#106. Construct Binary Tree from Inorder and Postorder Traversall

    一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 来源:http ...

  2. ROS(indigo)国外开源示例包括多机器人控制等基于V-Rep和Gazebo的仿真

    ROS(indigo)国外开源示例包括多机器人的V-Rep和Gazebo仿真等 1 micros_swarm_framework 使用超级经典的stage. http://wiki.ros.org/m ...

  3. 欢迎进入我的个人博客 anzhan.me

    CSDN的博客依旧会更新,但是还是专注于技术. 个人的博客 http://anzhan.me 不单单会同步csdn的技术文章,还会有个人的更多私人的分享,包括旅行日记.欢迎各位朋友经常去看看,大家有私 ...

  4. Linux IPC实践(2) --匿名PIPE

    管道概念 管道是Unix中最古老的进程间通信的形式,我们把从一个进程连接到另一个进程的一个数据流称为一个"管道", 管道的本质是固定大小的内核缓冲区; 如:ps aux | gre ...

  5. Google浏览器设置搜索打开新的标签页

    每次用google搜索的时候,点击进去原来的搜索页面就不见了 ,其实可以设置打开新的标签页 1.登陆Chrome 2.登陆这个网址https://www.google.com/preferences ...

  6. 【算法导论】最小生成树之Kruskal法

    在图论中,树是指无回路存在的连通图.一个连通图的生成树是指包含了所有顶点的树.如果把生成树的边的权值总和作为生成树的权,那么权值最小的生成树就称为最小生成树.因为最小生成树在实际中有很多应用,所以我们 ...

  7. Leetcode_136_Single Number

    本文是在学习中的总结,欢迎转载但请注明出处:http://blog.csdn.net/pistolove/article/details/42713315 Given an array of inte ...

  8. 知名IT公司的年度大会合集

    很多知名的IT公司都有年度大会,比如说谷歌,微软,Adobe,甲骨文,苹果等等.在这些公司的年度大会上,都会展示一些公司比较前沿的产品.看看这些大会的视频(也可以参会,但是门票可是非常贵的),对我们了 ...

  9. OS X升级到10.11后Xcode6.4界面无iOS device选择栏的解决办法

    原来在Xcode6.4项目运行按钮右侧会有一个可以选择设备或模拟器的选择栏,但是升级后没有了.但是Xcode7.0.1打开同样的项目会有显示. 简单找了一下无果后,发现咋Xcode顶部菜单里可以找到切 ...

  10. Linux - 停机常用的anacron

    什么是 anacron anacron 并不是用来取代 crontab 的,anacron 存在的目的就在於我们上头提到的,在处理非 24 小时一直启动的 Linux 系统的 crontab 的运行! ...