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. 1.5V升5V芯片,1.5V升5V电路图规格书

    常用的 5号,7号等 1.5V 干电池满电电压在 1.6V 左右,干电池输出耗电电压在 1V.适用PW5100,在 0.9V 时还能输出,彻底榨干干电池的电量. 1.5V 升5V 的芯片:PW5100 ...

  2. JAVA获取当前文件路径this.getClass().getResource方法详细讲解

    public class Test { public void run() { // TODO Auto-generated method stub System.out.println(" ...

  3. ryu安装

    $ python3 -V Python 3.7.2 $ git clone https://github.com/faucetsdn/ryu.git $ cd ryu $ sudo pip3 inst ...

  4. MySQL如何加锁控制并发

    目录 前言 一.乐观锁 添加version字段 二.悲观锁 读锁 全表锁(LOCK TABLE 表 READ) 行锁(SELECT ... LOCK IN SHARE MODE) 写锁 全表锁(LOC ...

  5. 遍历仓库里的 commit log 替换author

    #!/bin/sh # 遍历仓库里的 commit log, 替换author git filter-branch --env-filter ' an="$GIT_AUTHOR_NAME&q ...

  6. SICP 解题集 — SICP 解题集 https://sicp.readthedocs.io/en/latest/

    SICP 解题集 - SICP 解题集 https://sicp.readthedocs.io/en/latest/

  7. How Load Balancing Policies Work

    How Load Balancing Policies Work https://docs.cloud.oracle.com/en-us/iaas/Content/Balance/Reference/ ...

  8. AES加密模式

    https://baike.baidu.com/item/高级加密标准/468774 AES加密模式 对称/分组密码一般分为流加密(如OFB.CFB等)和块加密(如ECB.CBC等).对于流加密,需要 ...

  9. 6到8个月如何达到三年加得前端经验,对标P7,“慕课网 Java工程师2020”

    百度网盘链接:https://pan.baidu.com/s/1xshLRO3ru0LAsQQ0pE67Qg 提取码:bh9f   阶段一:课程设计及前端创建脚手架开发 第1周   需求分析和架构设计 ...

  10. 一本通提高篇——斜率优化DP

    斜率优化DP:DP的一种优化形式,主要用于优化如下形式的DP f[i]=f[j]+x[i]*x[j]+... 学习可以参考下面的博客: https://www.cnblogs.com/Xing-Lin ...