codeforces 8B
2 seconds
64 megabytes
standard input
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.
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
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的更多相关文章
- Codeforces Gym 100269F Flight Boarding Optimization 树状数组维护dp
Flight Boarding Optimization 题目连接: http://codeforces.com/gym/100269/attachments Description Peter is ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
- CodeForces - 261B Maxim and Restaurant
http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...
- CodeForces - 696B Puzzles
http://codeforces.com/problemset/problem/696/B 题目大意: 这是一颗有n个点的树,你从根开始游走,每当你第一次到达一个点时,把这个点的权记为(你已经到过不 ...
随机推荐
- 中间件:ElasticSearch组件RestHighLevelClient用法详解
本文源码:GitHub·点这里 || GitEE·点这里 一.基础API简介 1.RestHighLevelClient RestHighLevelClient的API作为ElasticSearch备 ...
- 面试官:你说说ReentrantLock和Synchronized区别
大家好!又和大家见面了.为了避免面试尴尬,今天同比较通俗语言和大家聊下ReentrantLock和Synchronized区别! 使用方式 Synchronized可以修饰实例方法,静态方法,代码块. ...
- Memcached与Redis对比及其优劣分析
国外讨论 本文主要总结缓存Redis和Memcached的区别,总结之前先参考外国知乎上的一篇问答:<Is memcached a dinosaur in comparison to Redis ...
- C++旋转数组(三种解法详解)
题目描述 给定一个数组,将数组中的元素向右移动 k 个位置,其中 k 是非负数. 附加要求 尽可能想出更多的解决方案,至少有三种不同的方法可以解决这个问题. 你可以使用空间复杂度为 O(1) 的 原地 ...
- Index-Only Scans and Covering Indexes
小结: 1.覆盖索引 回表 2. All indexes in PostgreSQL are secondary indexes, meaning that each index is stored ...
- python 基础二-----数据类型和控制语句
一.数据类型: 1)数据类型 1.整数(int) 2.浮点数(float) 3.字符串(string) 4.列表(list) 5. 元组(tuple) 6.字典(dict): key和value是一一 ...
- Hadoop----hdfs dfs常用命令的使用
用法 -mkdir 创建目录 Usage:hdfs dfs -mkdir [-p] < paths> 选项:-p 很像Unix mkdir -p,沿路径创建父 ...
- Preliminaries for Benelux Algorithm Programming Contest 2019
A. Architecture 如果行最大值中的最大值和列最大值中的最大值不同的话,那么一定会产生矛盾,可以手模一个样例看看. 当满足行列最大值相同条件的时候,就可以判定了. 因为其余的地方一定可以构 ...
- hdu 4352 XHXJ's LIS(数位dp+状压)
Problem Description #define xhxj (Xin Hang senior sister(学姐)) If you do not know xhxj, then carefull ...
- Codeforces Global Round 8 B. Codeforces Subsequences(构造)
题目链接:https://codeforces.com/contest/1368/problem/B 题意 构造最短的至少含有 $k$ 个 $codeforces$ 子序列的字符串. 题解 如下表: ...