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. 【Unity Tips】备忘录(扫盲篇)

    写在前面 Unity3D虽然是个非常方便的游戏引擎,但还是有一些地方会产生一些让人莫名其妙的问题,而且debug半天也不知道到底哪里错了.往往在经过了大量的log之后,也许我们才顿悟,原来Unity内 ...

  2. iOS中 DataBase SQL数据库 UI_高级

    SQL(Structured query Lauguage) :结构化 查询 语言 1.创建表格的SQL语句 create table if not exists Teacher(tea_id int ...

  3. 认识 SurfaceView

    SurfaceView是基于View视图进行扩展的视图类,适用于2D游戏开发,主要特点有: [1]surfaceView中对于画布的重绘是由一个新的线程去绘制,因此可以处理一些耗时的操作 [2]sur ...

  4. AngularJS进阶(二十九)AngularJS项目开发技巧之localStorage存储

    AngularJS项目开发技巧之localStorage存储       注: localStorage深度学习 绪 项目开发完毕,测试阶段发现后台管理端二维码生成有问题,问题在于localStora ...

  5. Flash Media Live Encoder 使用帮助

    翻译了一下Flash Media Live Encoder的帮助内容. Flash Media Live Encoder包含两个工具: Flash Media Live Encoder GUI(图 ...

  6. 让你的动画不再生硬 Android插值器Interpolator使用秘籍

    有木有厌烦生硬的动画效果,想不想让你的动画变得圆滑且 欢迎收看本期的走进科学... 停,停,别打了,(.﹏.*) 我错了-- 我们要达到的效果: 先来回顾一下普通动画的用法吧. * 缩放动画 Scal ...

  7. Leetcode_141_Linked List Cycle

    本文是在学习中的总结,欢迎转载但请注明出处:http://blog.csdn.net/pistolove/article/details/42833739 Given a linked list, d ...

  8. centos6.5 rsync+inotify实现服务器之间文件实时同步

    1. rsync的优点与不足 与传统的cp.tar备份方式相比,rsync具有安全性高.备份迅速.支持增量备份等优点,通过rsync可以解决对实时性要求不高的数据备份需求,例如定期的备份文件服务器数据 ...

  9. RHEL6.4上升级python从2.6.6到2.7.3

    RHEL6.4上升级python从2.6.6到2.7.3 原始安装好的redhat6.4上的python版本是2.6.6,不能满足实际需要.升级的方法很多,从源码升级或者从rpm包升级.其中从rpm包 ...

  10. AngularJS进阶(十)AngularJS改变元素显示状态

    AngularJS改变元素显示状态 前言 本文描述使用AngularJS提供的ng-show和ng-hide指令实现自动监听某布尔型变量来改变元素显示状态. 控制html元素显示和隐藏有n种方法:ht ...