Codeforces 322C Ciel and Robot【思维+模拟】细节很多= =
来源:互联网 发布:mac连wifi需要wpa2密码 编辑:程序博客网 时间:2024/06/04 18:29
题目大意:
按照给出的走路顺序无限重复下去,问能否走到点(a,b),起点在(0,0);
思路:
细节很多。
①我们首先模拟多次重复,如果能够走到终点,那么就是Yes.
②否则我们记下模拟走一回合到达的位子xx,yy.如果此时一回合的走向将与目标点相反走向,结果就是No.如果此时xx==0&&yy==0,结果也是No
③除上述两种情况以外,我们再模拟一次走一回合的过程,当我们走到点(x,y)的时候,我们如果有:
x+K*xx==a&&y+K*yy==b,那么结果就是Yes.否则整个过程不能通过循环来得到,结果也是No.
Ac代码:
#include<stdio.h>#include<string.h>#include<iostream>using namespace std;#define ll __int64char a[1500];int main(){ ll A,B; while(~scanf("%I64d%I64d",&A,&B)) { scanf("%s",a); ll n=strlen(a); ll xx,yy; xx=yy=0; int flag=0; int tx=0,ty=0; for(int i=0;i<100000;i++) { for(int j=0;j<n;j++) { if(tx==A&&ty==B)flag=1; if(a[j]=='U')ty++; if(a[j]=='D')ty--; if(a[j]=='L')tx--; if(a[j]=='R')tx++; if(tx==A&&ty==B)flag=1; } } for(ll i=0; i<n; i++) { if(xx==A&&yy==B)flag=1; if(a[i]=='U')yy++; if(a[i]=='D')yy--; if(a[i]=='L')xx--; if(a[i]=='R')xx++; if(xx==A&&yy==B)flag=1; } if(flag==1) { printf("Yes\n"); continue; } if(xx==yy&&xx==0) { printf("No\n"); continue; } if(A*xx<0||B*yy<0) { printf("No\n"); continue; } ll x=0,y=0; for(ll i=0; i<n; i++) { if((A-x)*yy==(B-y)*xx) { if(xx!=0&&(A-x)%xx==0) flag=1; if(yy!=0&&(B-y)%yy==0) flag=1; } if(a[i]=='U')y++; if(a[i]=='D')y--; if(a[i]=='L')x--; if(a[i]=='R')x++; if((A-x)*yy==(B-y)*xx) { if(xx!=0&&(A-x)%xx==0) flag=1; if(yy!=0&&(B-y)%yy==0) flag=1; } } if(flag==1)printf("Yes\n"); else printf("No\n"); }}
阅读全文
0 0
- Codeforces 322C Ciel and Robot【思维+模拟】细节很多= =
- CF 322C. Ciel and Robot 枚举+模拟
- CodeForces 321A Ciel and Robot(模拟)
- codeforces A. Ciel and Robot
- Codeforces Round #190 (Div. 2)-C. Ciel and Robot
- Codeforces Round 190 div.2 322C 321A Ciel and Robot
- CodeForces 321A Ciel and Robot[暴力]
- CodeForces 321 A - Ciel and Robot
- CodeForces 321A Ciel and Robot
- CF 322C - Ciel and Robot 计算周期
- Codeforces 322D Ciel and Duel【思维+费用流】
- CodeForces 321A Ciel and Robot(数学模拟)
- Codeforces 321A Ciel and Robot 枚举答案
- CodeForces 321A Ciel and Robot(数学模拟 枚举答案)
- Codeforces 752C Santa Claus and Robot 思维
- 【Codeforces 748 C Santa Claus and Robot】+ 思维
- codeforces 322 A Ciel and Dancing
- codeforces 322 B Ciel and Flowers
- h5输入框调起ios端键盘fixed失效
- 安卓EventBus的使用
- mybatis关系映射之一对多和多对一
- Idea、Eclipse 添加Maven依赖
- Sqlserver根据字段查找表和根据字段值查找表的几个方法
- Codeforces 322C Ciel and Robot【思维+模拟】细节很多= =
- c++ vector(向量)使用方法详解(顺序访问vector的多种方式)
- 下拉多选
- 串口设备数据的接收和处理
- CPP入门基础知识(一)
- 蓝牙模块HC-05的测试
- Linux基础知识之挂载详解(mount,umount及开机自动挂载)
- Go学习笔记(一)
- 实习日志(第六周)