zoukankan      html  css  js  c++  java
  • O

    O - Ciel and Robot
    Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u
    Submit Status
    Appoint description: 

    Description

    Fox Ciel has a robot on a 2D plane. Initially it is located in (0, 0). Fox Ciel code a command to it. The command was represented by strings. Each character of s is one move operation. There are four move operations at all:

    • 'U': go up, (x, y)  →  (x, y+1);
    • 'D': go down, (x, y)  →  (x, y-1);
    • 'L': go left, (x, y)  →  (x-1, y);
    • 'R': go right, (x, y)  →  (x+1, y).

    The robot will do the operations in s from left to right, and repeat it infinite times. Help Fox Ciel to determine if after some steps the robot will located in (a, b).

    Input

    The first line contains two integers a and b, ( - 109 ≤ a, b ≤ 109). The second line contains a string s (1 ≤ |s| ≤ 100s only contains characters 'U', 'D', 'L', 'R') — the command.

    Output

    Print "Yes" if the robot will be located at (a, b), and "No" otherwise.

    Sample Input

    Input
    2 2
    RU
    Output
    Yes
    Input
    1 2
    RU
    Output
    No
    Input
    -1 1000000000
    LRRLU
    Output
    Yes
    Input
    0 0
    D
    Output
    Yes
    const int maxn = 300;
    char op[maxn];
    struct Point
    {
        int x;
        int y;
    };
    vector<Point> p;
    int main() 
    {
        //freopen("in.txt","r",stdin);
        int x,y;
        while(cin>>x>>y)
        {
            p.clear();
            scanf("%s",op);
            int len = strlen(op);
            int X = 0;
            int Y = 0;
            p.push_back((Point){0,0});
            rep(i,0,len)
            {
                if(op[i] == 'L') X--;
                if(op[i] == 'R') X++;
                if(op[i] == 'U') Y++;
                if(op[i] == 'D') Y--;
                p.push_back((Point){X,Y});
            }
            int flag = 0;
            rep(i,0,p.size())
            {
                if(X == 0 && Y)
                {
                    if(x == p[i].x &&  (y - p[i].y)%Y == 0 && (y - p[i].y)/Y >= 0)
                    {
                        flag = 1;
                        break;
                    }
                    continue;
                }
                if(Y == 0 && X)
                {
                    if(y == p[i].y && (x - p[i].x)%X == 0 && (x - p[i].x)/X >= 0)
                    {
                         flag = 1;
                         break;
                    }
                    continue;
                }
                if(X == 0 && Y == 0)
                {
                   if( x == p[i].x && y == p[i].y)
                   {
                       flag = 1;
                       break;
                   }
                   continue;
                }
                if((x - p[i].x)%X == 0 &&  (y - p[i].y)%Y == 0 && ((x - p[i].x)/X == (y - p[i].y)/Y) && (x - p[i].x)/X >= 0)
                {
                    flag = 1;
                    break;
                }
            }
            if(flag)
                cout<<"Yes"<<endl;
            else
                cout<<"No"<<endl;
        }
        return 0;
    }
  • 相关阅读:
    深入理解JVM(六)——类加载器原理
    深入理解JVM(五)——垃圾回收器
    深入理解JVM(四)——垃圾回收算法
    Let's Encrypt,免费好用的 HTTPS 证书
    开源框架(整理)
    【转】JS组件系列——Bootstrap组件福利篇:几款好用的组件推荐(二)
    C#开源项目大全
    window平台搭建Hudson服务器
    Git 常用命令
    Mongodb Windows 集群
  • 原文地址:https://www.cnblogs.com/DreamHighWithMe/p/3430049.html
Copyright © 2011-2022 走看看