zoukankan      html  css  js  c++  java
  • cf 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).

    Sample test(s)
    input
    LLUUUR
    output
    OK
    input
    RRUULLDD
    output
    BUG
    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<string>
    #include<cmath>
    #include<cstdlib>
    #include<algorithm>
    using namespace std;
    string s;
    int a[410][410];
    int main()
    {
          cin>>s;
          int x=200,y=200;
          for(int i=0;i<s.length();i++)
          {
                a[x][y]=1;
                if(s[i]=='U') x--;
                if(s[i]=='L') y--;
                if(s[i]=='D') x++;
                if(s[i]=='R') y++;
                if(a[x-1][y]+a[x][y-1]+a[x+1][y]+a[x][y]+a[x][y+1]>1)
                {
                      printf("BUG
    ");
                      return 0;
                }
          }
          printf("OK
    ");
          return 0;
    }
    

      

  • 相关阅读:
    《Effective Java 第三版》——第五章 泛型
    线性代数在数据科学中的十个强大应用(一)
    ​知识图谱里的知识存储:neo4j的介绍和使用
    一份从入门到精通NLP的完整指南 | NLPer
    NeurIPS审稿引发吐槽大会,落选者把荒唐意见怼了个遍:“我谢谢你们了”
    知识图谱与机器学习|KG入门 -- Part2 建立知识图谱
    知识图谱与机器学习 | KG入门 -- Part1-b 图深度学习
    ​知识图谱与机器学习 | KG入门 -- Part1 Data Fabric
    使用特定领域的文档构建知识图谱 | 教程
    ICCV 2019|70 篇论文抢先读,含目标检测/自动驾驶/GCN/等(提供PDF下载)
  • 原文地址:https://www.cnblogs.com/a972290869/p/4222558.html
Copyright © 2011-2022 走看看