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> ...
随机推荐
- python selenium登陆网易云音乐
from selenium import webdriver import time driver=webdriver.Chrome() driver.get("http://music.1 ...
- 关于一些对location认识的误区
1. location 的匹配顺序是“先匹配正则,再匹配普通”. 矫正: location 的匹配顺序其实是“先匹配普通,再匹配正则”.我这么说,大家一定会反驳我,因为按“先匹配普通,再匹配正则”解释 ...
- loadrunner 测试问题汇总
1.关于Error -27791: Error -27790:Error -27740: 错误如下: Action.c(198): Error -27791: Server ...
- centos7-sar工具的安装过程及其简单应用
一.sar工具安装 1.进入yum配置文件目录: cd /etc/yum.repos.d/ 2.vi CentOS-Base.repo命令创建文件CentOS-Base.repo 文件内容见网页:ht ...
- SilverLight高亮显示文本
文笔不好,就长话短说,就是想实现这样的效果,比如在成都二环路南一段一号附一号凤舞九天网吧 ,搜索 二环路 九天网吧 然后结果中高亮显示. <local:TextBlockHighLight Te ...
- 使用coding云作为git远程库
1.在命令行中创建GIT仓库 mkdir DriveAssistant cd DriveAssistant git init echo "# DriveAssistant" > ...
- beego学习笔记(4):开发文档阅读(1)
1.beego的设计是高度模块化的.每个模块,都可以单独使用.一共八大模块: cache;session;log;orm;context;httplibs;toolbox 2.beego的执行逻辑 3 ...
- 并发queue
在并发队列上JDK提供了两套实现,一个是以ConcurrentLinkedQueue为代表的高性能队列,一个是以BlockingQueue接口为代表的阻塞队列,无论哪种都继承自Queue. 一.Con ...
- 小程序授权怎么写 , 用户点击取消授权 调用 wx.authorize
点击获取授权 onLoad: function (options) { console.log("onLoad====="); var that=this; wx.getUserI ...
- beego orm操作mysql数据库
慢慢弄起来~~ 按官方操作文档试一下. 那个err重复和user编号问题,以后再弄.. package main import ( "fmt" "github.com/a ...