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经典实例
文件结构: index.php 主页和添加页 show.php 查看留言页 ly.db 文本保存页 doAdd.php 添加功能页 doDel.php 删除功能页 index.php <htm ...
- win8扁平风格的物流公司网站后台管理模板——后台
链接:http://pan.baidu.com/s/1o79Zp2M 密码:tqrz
- php审计学习:xdcms2.0.8注入
注入点Fields: 注册页面会引用如下方法: $fields 变量是从 $fields=$_POST['fields']; 这里获取, 在代码里没有过滤. 打印 fields 数据查看: 从代码上看 ...
- python之微信公众号开发(基本配置和校验)
前言 最近有微信公众号开发的业务,以前没有用python做过微信公众号开发,记录一下自己的学习和开发历程,共勉! 公众号类型 订阅号 普通订阅号 认证订阅号 服务号 普通服务号 认证服务号 服务方式 ...
- 75.VS2013和opencv3.1.0开发环境配置
首先要做的就是 开发环境配置,具体过程如下: Step 1:OpenCV环境变量配置 我的电脑--->属性--->高级系统设置--->高级--->环境变量--->系统变量 ...
- Codeforces Round #441 (Div. 2)
Codeforces Round #441 (Div. 2) A. Trip For Meal 题目描述:给出\(3\)个点,以及任意两个点之间的距离,求从\(1\)个点出发,再走\(n-1\)个点的 ...
- [ python ] 网络编程(1)
在本地电脑上有两个python文件 regist.py .login.py 一个注册,一个登录.这两个python一个是写用户信息,一个是读用户信息,要怎么做呢? 通过之前的知识,我们可以通过 reg ...
- C语言小程序之整除
看到有人要求用C语言写这样一个小程序,就拿来温习一下 需求:输出从1到2015这2015个自然数中,能被4或5整除,但不能被30整除的数,并计算有多少个数. #include<stdio.h ...
- netty 基础知识
http://my.oschina.net/bieber/blog/406799 线程模型 http://hongweiyi.com/2014/01/netty-4-x-thread-model/ h ...
- postgresql 数据导入导出
[转] 分类: postgresql2013-06-09 10:21 2486人阅读 评论(0) 收藏 举报 一.导出数据库及具体表 1.导出数据库:方式一:pg_dump -U postgres ...