Codeforces 321 A-ciel and Robot

Source: Internet
Author: User

" topic link ": Click here~~

" The main idea": A robot robot can act according to a given instruction, give you four kinds of instructions, robot initial position is (0,0), the instruction is out, robot will repeat the action, judge whether in the case of infinite action can pass the point (n,m).

" problem-solving ideas " in fact, carefully simulated, you can find that there is a cycle, judge can, see the Code bar ~ ~

Code:

#include <iostream> #include <algorithm> #include <bits/stdc++.h>using namespace std;const int n=105;    int N,m,c,t,ans,res,tmp;char str[n];int X[n],y[n];int main () {int x, y;        while (~SCANF ("%d%d", &x,&y)) {memset (x,0,sizeof (x));        memset (y,0,sizeof (Y));        scanf ("%s", str+1);        int Len=strlen (str+1);            if (x==0&&y==0) {puts ("Yes");        return 0;            } else{bool flag=0;            int j=0,xx=x;            int yy=y;            int uu=0,dd=0,ll=0,rr=0; for (int i=0, i<=len; ++i) {switch (Str[i]) {case ' U ': x[i]=x[i-1],y[i]                    =y[i-1]+1;///y[0]=1;                Break                    Case ' D ': x[i]=x[i-1],y[i]=y[i-1]-1;                Break                    Case ' L ': x[i]=x[i-1]-1,y[i]=y[i-1];                Break Case ' R ': x[i]=x[i-1]+1,y[i]=y[i-1];/X[0]=1, break;   }/* if (str[i]== ' U ') {x[i]=x[i-1],y[i]=y[i-1]+1; Uu++;///yy+=1} else if (str[i]== ' D ') {x[i]=x    [I-1],y[i]=y[i-1]-1; Dd++;///yy-=1} else if (str[i]== ' L ') {x[i]=x[    I-1]-1,Y[I]=Y[I-1]; Ll++;///xx-=1} else {X[i]=x[i-1]+1,y[i]=y[i    -1];            Xx+=1} */} int zq;                for (int i=0; i<=len; ++i) {//2 2 int za=xx-x[i];///2-x[0]=1, int zb=yy-y[i];///2-y[0]=1,                Zq= (X[len]!=0?za/x[len]:(y[len]!=0?zb/y[len]:1));         if (x[len]*zq==za&&y[len]*zq==zb&&zq>=0)///if (zq>=0) {puts ("Yes");            return 0;        }} puts ("No"); }} return 0;} /*2 2ru1 2ru-1 1000000000lrrlu0 0dyesnoyesyes*/


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Codeforces 321 A-ciel and Robot

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.