Codeforces Beta Round #8 B. Obsession with Robots 暴力
B. Obsession with Robots
题目连接:
http://www.codeforces.com/contest/8/problem/B
Description
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).
Sample Input
LLUUUR
Sample Output
OK
Hint
题意
有一个迷宫,他不知道某些位置是障碍还是空地,但是会给你一个移动的指令
然后问你这个移动的指令是否走的是最短路
题解:
就只假设走过的地方是空地好了,最后再跑一个bfs
代码
#include<bits/stdc++.h>
using namespace std;
const int maxn = 205;
int M[maxn][maxn];
int T[maxn][maxn];
int vis[maxn][maxn];
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
string s;
int main()
{
for(int i=0;i<maxn;i++)
for(int j=0;j<maxn;j++)
M[i][j]=1;
cin>>s;
int nowx=maxn/2,nowy=maxn/2;
M[nowx][nowy]=0;
for(int i=0;i<s.size();i++)
{
if(s[i]=='L')nowy++;
if(s[i]=='U')nowx++;
if(s[i]=='D')nowx--;
if(s[i]=='R')nowy--;
M[nowx][nowy]=0;
}
int enx=nowx,eny=nowy;
nowx=maxn/2,nowy=maxn/2;
queue<pair<int,int> >Q;
Q.push(make_pair(nowx,nowy));
vis[nowx][nowy]=1;
while(!Q.empty())
{
pair<int,int>now = Q.front();
Q.pop();
for(int i=0;i<4;i++)
{
pair<int,int>next=now;
next.first+=dx[i];
next.second+=dy[i];
if(vis[next.first][next.second])continue;
if(M[next.first][next.second])continue;
T[next.first][next.second]=T[now.first][now.second]+1;
vis[next.first][next.second]=1;
Q.push(next);
}
}
if(T[enx][eny]<s.size())cout<<"BUG"<<endl;
else cout<<"OK"<<endl;
}
Codeforces Beta Round #8 B. Obsession with Robots 暴力的更多相关文章
- Codeforces Beta Round #37 C. Old Berland Language 暴力 dfs
C. Old Berland Language 题目连接: http://www.codeforces.com/contest/37/problem/C Description Berland sci ...
- Codeforces Beta Round #80 (Div. 2 Only)【ABCD】
Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...
- Codeforces Beta Round #62 题解【ABCD】
Codeforces Beta Round #62 A Irrational problem 题意 f(x) = x mod p1 mod p2 mod p3 mod p4 问你[a,b]中有多少个数 ...
- Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】
Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...
- Codeforces Beta Round #13 C. Sequence (DP)
题目大意 给一个数列,长度不超过 5000,每次可以将其中的一个数加 1 或者减 1,问,最少需要多少次操作,才能使得这个数列单调不降 数列中每个数为 -109-109 中的一个数 做法分析 先这样考 ...
- Codeforces Beta Round #79 (Div. 2 Only)
Codeforces Beta Round #79 (Div. 2 Only) http://codeforces.com/contest/102 A #include<bits/stdc++. ...
- Codeforces Beta Round #77 (Div. 2 Only)
Codeforces Beta Round #77 (Div. 2 Only) http://codeforces.com/contest/96 A #include<bits/stdc++.h ...
- Codeforces Beta Round #76 (Div. 2 Only)
Codeforces Beta Round #76 (Div. 2 Only) http://codeforces.com/contest/94 A #include<bits/stdc++.h ...
- Codeforces Beta Round #75 (Div. 2 Only)
Codeforces Beta Round #75 (Div. 2 Only) http://codeforces.com/contest/92 A #include<iostream> ...
随机推荐
- php文件上传——php经典实例
php文件上传——php经典实例 表单页 <html> <head> <title>文件上传</title> <meta charset='ut ...
- spring-boot-资源处理
WebMvcConfigurerAdapter 使用 1.实现 HandlerInterceptorAdapter 2.添加拦截器 重写WebMvcConfigurerAdapter中的addInte ...
- 33、求按从小到大的顺序的第N个丑数
一.题目 把只包含因子2.3和5的数称作丑数(Ugly Number).例如6.8都是丑数,但14不是,因为它包含因子7. 习惯上我们把1当做是第一个丑数.求按从小到大的顺序的第N个丑数. 二.解法 ...
- 64_t1
TOPCOM-0.17.8-2.fc26.x86_64.rpm 13-Feb-2017 22:09 269054 TOPCOM-devel-0.17.8-2.fc26.i686.rpm 13-Feb- ...
- java 1.8 新特性 stream
并发提升 java 中Stream类似于hadoop中的数据分析的思路,只不过hadoop大,用的是多台机算机的计算生态,而java stream使用的单台计算机中的多cpu分析一块数据的过程.通过 ...
- java你应该学会什么
给初学者之一:浅谈java及应用学java 先说什么是Javajava是一种面向对象语言,真正的面向对象,任何函数和变量都以类(class)封装起来至于什么是对象什么是类,我就不废话了关于这两个概念的 ...
- ireport报表,打印时,报表加载失败的解决方法
1.报表加载失败图示 2.解决方法 原创作者:DSHORE 作者主页:http://www.cnblogs.com/dshore123/ 原文出自:http://www.cnblogs.com/dsh ...
- Funny Car Racing(最短路变形)
描述 There is a funny car racing in a city with n junctions and m directed roads. The funny part is: e ...
- ECMA6
let关键字 用来替代var 的关键字,不能重复定义一个变量 举例: for(var i=0; i<5; i++){ setTimeout(function(){ ...
- 计算 Python (list or array) 相同索引元素相等的个数
上代码: a = [2, 3, 3, 1, 1, 3, 3, 3, 2, 1, 3, 1, 3, 2, 2, 2, 3, 1, 2, 3, 2, 3, 1, 1, 2, 1, 1, 1, 2, 2, ...