B. Obsession with Robots
time limit per test

2 seconds

memory limit per test

64 megabytes

input

standard input

output

standard output

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.

Input

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.

Output

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

Examples
input
LLUUUR
output
OK
input
RRUULLDD
output
BUG
 这题好难读。意思是给你一条路径判断在给定的路径中是否还能找到能短的路。
 1 #include <cstdio>
2 #include <cstring>
3 #include <string>
4 #include <string.h>
5 #include <cmath>
6 #include <iostream>
7 #include <algorithm>
8 #include <queue>
9 #include <stack>
10 #include <vector>
11 typedef long long ll;
12 using namespace std;
13 bool mp[311][311];
14 int main() {
15 string s;
16 cin>>s;
17 int x=200,y=200;
18 for(int i=0;i<s.size();++i)
19 {
20 mp[x][y]=1;
21 if(s[i]=='L') x--;
22 if(s[i]=='R') x++;
23 if(s[i]=='U') y++;
24 if(s[i]=='D') y--;
25 if(mp[x][y]+mp[x-1][y]+mp[x+1][y]+mp[x][y-1]+mp[x][y+1]>1)
26 {
27 cout<<"BUG"<<endl;
28 return 0;
29 }
30 }
31 cout<<"OK"<<endl;
32 return 0;
33 }

codeforces 8B的更多相关文章

  1. Codeforces Gym 100269F Flight Boarding Optimization 树状数组维护dp

    Flight Boarding Optimization 题目连接: http://codeforces.com/gym/100269/attachments Description Peter is ...

  2. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  3. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  4. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  5. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  6. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

  7. CodeForces - 274B Zero Tree

    http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...

  8. CodeForces - 261B Maxim and Restaurant

    http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...

  9. CodeForces - 696B Puzzles

    http://codeforces.com/problemset/problem/696/B 题目大意: 这是一颗有n个点的树,你从根开始游走,每当你第一次到达一个点时,把这个点的权记为(你已经到过不 ...

随机推荐

  1. 以我的亲身经历,聊聊学python的流程,同时推荐学python的书

    因为干活要用到,所以我大概于19年5月开始学python,大概学了1个月后,我就能干公司的活了,而且这python项目还包含了机器学习等要素,大概3个月后,我还承担了项目里开发机器学习数据分析的任务. ...

  2. Markdown特殊字符、数学公式汇总

    引自:https://blog.csdn.net/weixin_39653948/article/details/104621249

  3. BeetleX大数据之产品分析服务

        数据规模过于庞大?数据标签过多难以管理?增加新的分析维度需要配置?这些beetlex.io都能轻松解决,即导即用,数据标签自动管理,轻易实现多种维度数据分析处理.接下介绍BeetleX针对产品 ...

  4. Mysql 中写操作时保驾护航的三兄弟!

    这期的文章主要是讲述写操作过程中涉及到的三个日志文件,看过前几期的话可能你或多或少已经有些了解了(或者从别的地方也了解过).比如整个写操作过程中用到的两阶段提交,又或者是操作过程中涉及到的日志文件,但 ...

  5. jmeter-并发及常数吞吐量定时器设定

  6. 超精讲-逐例分析 CSAPP:实验2-Bomb!(下)

    好了话不多说我们书接上文继续来做第二个实验下面是前半部分实验的连接 5. 第五关 首先感觉应该是个递归问题 /* Round and 'round in memory we go, where we ...

  7. ubuntu 14.04下安装 mysql-workbench

    直接在命令行下运行下面命令: sudo apt-get install mysql-workbench 安装完,都可以在Dash中找到 "mysql" 就点击应用打开. 在data ...

  8. 选出ip记录表最近的10行数据

    w select * from wip where id>(select (select max(id)from wip)-10) ;

  9. LOJ10015扩散

    10015. 「一本通 1.2 练习 2」扩散   题目描述 一个点每过一个单位时间就会向 4 个方向扩散一个距离,如图所示:两个点 a .b 连通,记作e(a,b) ,当且仅当 a.b 的扩散区域有 ...

  10. Language Guide (proto3) | proto3 语言指南(十一)包

    Packages - 包 可以向.proto文件中添加可选的package明符,以防止协议消息类型之间的名称冲突. package foo.bar; message Open { ... } 然后你可 ...