当前位置: 代码迷 >> 综合 >> 2022.02.12翻译Obsession with Robots
  详细解决方案

2022.02.12翻译Obsession with Robots

热度:40   发布时间:2023-12-05 15:32:30.0

Obsession with Robots
题目(https://acs.jxnu.edu.cn/problem/CF8B)描述:
The whole world got obsessed with robots,and to keep pace with the progress, great Berland's programmer Draude decided to build his own robot. He was working hard at the robot. He taught it to walk the shortest path from one point to another, to record all its movements, but like in many Draude's programs, there was a bug — the robot didn't always walk the shortest path. Fortunately, the robot recorded its own movements correctly. Now Draude wants to find out when his robot functions wrong. Heh, if Draude only remembered the map of the field, where he tested the robot, he would easily say if the robot walked in the right direction or not. But the field map was lost never to be found, that's why he asks you to find out if there exist at least one map, where the path recorded by the robot is the shortest.

The map is an infinite checkered field, where each square is either empty, or contains an obstruction. It is also known that the robot never tries to run into the obstruction. By the recorded robot's movements find out if there exist at least one such map, that it is possible to choose for the robot a starting square (the starting square should be empty) such that when the robot moves from this square its movements coincide with the recorded ones (the robot doesn't run into anything, moving along empty squares only), and the path from the starting square to the end one is the shortest.

In one movement the robot can move into the square (providing there are no obstrutions in this square) that has common sides with the square the robot is currently in.

输入:
The first line of the input file contains the recording of the robot's movements. This recording is a non-empty string, consisting of uppercase Latin letters L, R, U and D, standing for movements left, right, up and down respectively. The length of the string does not exceed 100.

输出:
In the first line output the only word OK (if the above described map exists), or BUG (if such a map does not exist).

样例输入:
LLUUUR
样例输出:
OK
样例输入:
RRUULLDD
样例输出:
BUG

翻译:
整个世界对机器人痴迷,为了跟上时代的步伐,波兰伟大的科学家Draude决定建一个他自己的机器人。他十分努力。他教机器人用最短的路径从一点走到另一点,且记录了它的移动路径,但是像Draude的很多其他的程序一样,这里有一个bug:机器人不能总是按照最短路径走。幸运的是,机器人准确的记录的它自己的移动路径。现在Draude像要知道机器人什么时候会出错。嘿,如果Draude记得田野的地图,那么无论他在哪里测试机器人,他都可以轻易的判断机器人有没有按正确的路径走。但是田野的地图永远的不见了,那就是为什么他向你寻求帮助,找到是否存在至少一张地图,在地图上机器人所走路径是最短的。

地图是一片有着无限方格的区域,每个方格是空的或有障碍物。已知机器人不会尝试跑过障碍物。通过机器人的路径,找到这里是否至少存在一张地图,可能可以为机器人选择一个起始方格(起始方格必须是空的),当机器人从起始方格移动,它的移动路径和记录的移动路经相符(机器人不会跑向任何东西,只会在空方格内移动),并且是最短路径。

在一次移动过程中,机器人可以移向相邻的方格(方格内无障碍)。

输入:
第一行包含机器人移动路径的记录。为一个不包含空格的字符串,由大写字母L,R,U,和D组成,分别表示向左,右,上和下移动。字符串长度不超过100;
输出:
第一行输出一个单词OK(如果上述描述的地图存在)或BUG(如果那样的地图不存在)。
样例输入:
LLUUUR
样例输出:
OK
样例输入:
RRUULLDD
样例输出:
BUG