A. Ciel and Robot
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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|≤100, s 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 test(s)
input

2 2
RU

output

Yes

input

1 2
RU

output

No

input

-1 1000000000
LRRLU

output

Yes

input

0 0
D

output

Yes

Note

In the first and second test case, command string is "RU", so the robot will go right, then go up, then right, and then up and so on.

The locations of its moves are (0, 0) → (1, 0) → (1, 1) → (2, 1) → (2, 2) → ...

So it can reach (2, 2) but not (1, 2).

官方题解:

322C - Ciel and Robot 321A - Ciel and Robot

Note that after Ciel execute string s, it will moves (dx, dy).

And for each repeat, it will alway moves (dx, dy).

So the total movement will be k * (dx, dy) + (dx[p], dy[p]) which (dx[p], dy[p]) denotes the movement after execute first p characters.

We can enumerate p since (0 <= p < |s| <= 100), and check if there are such k exists.

Note that there are some tricks:

We can divide dx or dy directly because they both can become zero.

Another trick is that k must be non-negative.

Many people failed on this test case (which no included in the pretest):

-1 -1

UR

#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
int dx[111],dy[111];
int ta,tb;
char str[111];
int main()
{
    cin>>ta>>tb;
    cin>>str;
    memset(dx,0,sizeof(dx));
    memset(dy,0,sizeof(dy));
    int len=strlen(str);
    for(int i=0;i<len;i++)
    {
        if(str=='U')
        {
            dy[i+1]=dy+1;
            dx[i+1]=dx;
        }
        else if(str=='D')
        {
            dy[i+1]=dy-1;
            dx[i+1]=dx;
        }
        else if(str=='L')
        {
            dx[i+1]=dx-1;
            dy[i+1]=dy;
        }
        else if(str=='R')
        {
            dx[i+1]=dx+1;
            dy[i+1]=dy;
        }
    }
/*
    for(int i=0;i<=len;i++)
    {
        cout<<dx<<" and "<<dy<<endl;
    }
*/
    int ddx=dx[len],ddy=dy[len];
    int OK=0;
    if(ta==0&&tb==0) OK=1;
    if(!OK)
    for(int i=1;i<=len;i++)
    {
        if(ta==dx&&tb==dy)
        {
            OK=1;
            break;
        }
    }
    if(!OK)
    for(int i=0;i<len;i++)
    {
        int kx=ta-dx;
        int ky=tb-dy;
        if(ddx==0&&ddy==0)
        {
            if(kx==0&&ky==0)
            {
                OK=1;break;
            }
        }
        else if(ddx==0&&ddy!=0)
        {
            if(kx==0)
            {
                if(ky%ddy==0)
                {
                    if(ky/ddy>=0)
                    {
                        OK=1;
                        break;
                    }
                }
            }
        }
        else if(ddy==0&&ddx!=0)
        {
            if(ky==0)
            {
                if(kx%ddx==0)
                {
                    if(kx/ddx>=0)
                    {
                        OK=1;
                        break;
                    }
                }
            }
        }
        else if(ddx!=0&&ddy!=0)
        {
            if(kx%ddx==0&&ky%ddy==0)
            {
                int t1=kx/ddx;
                int t2=ky/ddy;
                if(t1==t2)
                {
                    if(t1>=0)
                    {
                        OK=1;
                        break;
                    }
                }
            }
        }
    }
    if(OK==1)
    {
        puts("Yes");
    }
    else puts("No");
    return 0;
}

CodeForces 321A的更多相关文章

  1. CodeForces 321A Ciel and Robot(数学模拟)

    题目链接:http://codeforces.com/problemset/problem/321/A 题意:在一个二维平面中,開始时在(0,0)点,目标点是(a.b),问能不能通过反复操作题目中的指 ...

  2. Codeforces Round 190 div.2 322C 321A Ciel and Robot

    唔...这题是数学题. 比赛时做出来,但题意理解错了,以为只要判断那点是不是在线上就行了,发现过不了样例就没提交. 思路:记录每一步的偏移,假设那点是在路径上的某步,然后回推出那一个周期的第一步,判断 ...

  3. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  4. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  5. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  6. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  7. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

  8. CodeForces - 274B Zero Tree

    http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...

  9. CodeForces - 261B Maxim and Restaurant

    http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...

随机推荐

  1. 【转】Linux Soclet编程

    原文地址:http://www.cnblogs.com/skynet/archive/2010/12/12/1903949.html “一切皆Socket!” 话虽些许夸张,但是事实也是,现在的网络编 ...

  2. 1.python的第一步

    学习python也有一段时间了,自认为基本算是入门了,想要写一些博客进行知识的汇总的时候.却发现不知道该从何说起了,因为python这门语言在语法上其实并不难,关键在于如何建立程序员的思维方式,而对于 ...

  3. vim代码补全-spf13,YouCompleteMe

    vim代码补全 现在的图形界面的IDE(Integrated Development Environment)一般具有语法高亮,语法检查,自动补全功能,大大提高了编程的效率. vim作为文本编辑器其强 ...

  4. ED/EP系列6《扩展应用》

    包括:电子钱包复合应用:电子钱包灰锁应用. 1. 复合应用模式 Ø INITIALIZE FOR CAPP PURCHASE(复合应用消费初始化): Ø UPDATE CAPP DATA CACHE( ...

  5. Linux ls -l内容详解

    ls -l是列出当前目录下所有文件信息 以下是实例: 具体的文字描述如下: 第1字段:  文件属性字段文件属性字段总共有10个字母组成,第一个字母表示文件类型,如果这个字母是一个减号”-”,则说明该文 ...

  6. oracle 分析函数(笔记)

    分析函数是oracle数据库在9i版本中引入并在以后版本中不断增强的新函数种类.分析函数提供好了跨行.多层次聚合引用值的能力.分析函数所展现的效果使用传统的SQL语句也能实现,但是实现方式比较复杂,效 ...

  7. microsoft azure Media Services 媒体服务解决方案

    用安全的方式为您随时随地跨设备传送媒体内容.提供可伸缩的端到端媒体解决方案 可用于高级视频工作流的云 实现奥运会规模的直播与点播媒体传送 高可用的编码和流式处理 支持 Flash.iOS.Androi ...

  8. App_Store - IOS应用审核的时隐私政策模板

    隐私政策  Poposoft尊重并保护所有使用服务用户的个人隐私权.为了给您提供更准确.更有个性化的服务,Poposoft会按照本隐私权政策的规定使用和披露您的个人信息.但Poposoft将以高度的勤 ...

  9. 服务器 IIS 发布网站 支持下载 apk 和 ipa

    方法/步骤   1 打开IIS服务管理器,找到服务器,右键-属性,打开IIS服务属性: 2 单击MIME类型下的"MIME类型"按钮,打开MIME类型设置窗口: 3 单击" ...

  10. generate the next AttestationNumber, 格式是ICD-EPRG-DEV-0000000001,ICD-EPRG-DEV-0000000002

    private static int GetNextAttestationNumber(string maxAttestationNumber) { //generate the next Attes ...