zoukankan      html  css  js  c++  java
  • codeforces 8B

    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 }
    View Code
  • 相关阅读:
    c# WinForm 定时执行某个后台操作 如把B文件夹下的文件Copy到A文件夹下
    c# 创建指定大小的空字符填充的文本文件 在指定位置读写相关内容
    c# DirectShow 通过IAMVideoProcAmp的Set方法 来设置视频图像的Brightness 调整亮度
    [转]灰度图像的腐蚀算法和细化算法(C#代码)
    利用fleximage实现图片上传
    利用acts_as_ferret实现全文检索
    纯CSS无hacks的跨游览器多列布局
    IE私有CSS样式属性一览
    利用thinking sphinx实现全文检索
    搭建rails运行环境
  • 原文地址:https://www.cnblogs.com/zmin/p/8376746.html
Copyright © 2011-2022 走看看