题目链接:http://codeforces.com/problemset/problem/321/A

题意:在一个二维平面中,開始时在(0,0)点,目标点是(a。b),问能不能通过反复操作题目中的指令,从原点移动到目标点。

分析:如果一次完毕全部的命令后。移动到了(xx,yy),而且从(Xi。Yi)反复操作k次指令到达目标点。则能够列出方程 Xi + k * xx = a && Yi + k * yy = b。然后解出k。推断k是否大于等于0就可以。

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef __int64 LL;
LL a, b, xx, yy;
LL X[150], Y[150];
int len;
bool check(LL x, LL y) {
LL tmp_x = a - x, tmp_y = b - y;
if(xx == 0) {
if(yy == 0) {
if(tmp_x == 0 && tmp_y == 0) return true;
else return false;
}
else {
if(tmp_y % yy == 0) {
if(tmp_y / yy >= 0 && tmp_x == 0) return true;
else return false;
}
else return false;
}
}
else {
if(yy == 0) {
if(tmp_x % xx == 0) {
if(tmp_x / xx >= 0 && tmp_y == 0) return true;
else return false;
}
else return false;
}
else {
if(tmp_x % xx == 0 && tmp_y % yy == 0) {
if(tmp_x / xx >= 0 && tmp_y / yy >= 0 && tmp_x / xx == tmp_y / yy) return true;
else return false;
}
else return false;
}
}
} int main() {
char op[150];
while(~scanf("%I64d%I64d", &a, &b)) {
scanf("%s", op);
if(a == 0 && b == 0) {
printf("Yes\n");
continue;
}
len = strlen(op);
LL x = 0, y = 0;
int FLAG = 0;
for(int i = 0; i < len; i++) {
if(op[i] == 'U') y++;
else if(op[i] == 'D') y--;
else if(op[i] == 'L') x--;
else if(op[i] == 'R') x++;
X[i] = x, Y[i] = y;
}
xx = X[len-1], yy = Y[len-1];
for(int i = 0; i < len; i++) {
if(check(X[i], Y[i])) {
FLAG = 1;
printf("Yes\n");
break;
}
}
if(!FLAG) printf("No\n");
}
return 0;
}

CodeForces 321A Ciel and Robot(数学模拟)的更多相关文章

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

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

  2. CodeForces 321A

    A. Ciel and Robot time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  3. Ciel and Robot

    C. Ciel and Robot time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  4. Codeforces G. Ciel the Commander

    题目描述: Ciel the Commander time limit per test 1 second memory limit per test 256 megabytes input stan ...

  5. CodeForces 321 A - Ciel and Robot

    [题目链接]:click here~~ [题目大意]:一个robot 机器人 .能够依据给定的指令行动,给你四种指令,robot初始位置是(0,0).指令一出.robot会反复行动,推断是否能在无限行 ...

  6. Codeforces Round #115 A. Robot Bicorn Attack 暴力

    A. Robot Bicorn Attack Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/17 ...

  7. CodeForces 321C Ciel the Commander

    Ciel the Commander Time Limit: 1000ms Memory Limit: 262144KB This problem will be judged on CodeForc ...

  8. Codeforces 321E Ciel and Gondolas

    传送门:http://codeforces.com/problemset/problem/321/E [题解] 首先有一个$O(n^2k)$的dp. # include <stdio.h> ...

  9. Codeforces 321D Ciel and Flipboard(结论题+枚举)

    题目链接   Ciel and Flipboard 题意  给出一个$n*n$的正方形,每个格子里有一个数,每次可以将一个大小为$x*x$的子正方形翻转 翻转的意义为该区域里的数都变成原来的相反数. ...

随机推荐

  1. Python 基本数据类型 (一) - 整数

    帮助文档网址: https://docs.python.org/3.7/tutorial/introduction.html 待补充

  2. opencv中的各种滤波设计

     这篇文章写得太好了 ,感觉自己实在没有办法去补充这方面的知识点 我打算把高斯滤波和双边滤波还好好补充下 这篇文章转载自一个美丽的才女:小魏 连接地址:http://blog.csdn.net/xia ...

  3. Verilog学习笔记基本语法篇(八)········ 结构说明语句

    Verilog中的任何过程都可以属于以下四种结构的说明语句; 1) initial;  2) always;  3) task;   4) function; 1) initial说明语句: 一个程序 ...

  4. ACM-ICPC 2018 沈阳赛区网络预赛 F. Fantastic Graph

    "Oh, There is a bipartite graph.""Make it Fantastic." X wants to check whether a ...

  5. Experimental considerations

    先知 重金属颗粒与气孔大小 气孔位置.密度与开合时间 角质层厚度 意外 叶子第二天掉落 样本没有放冰箱 高光谱仪器损坏 天气下雨/雪 仪器预约 楼顶/实验室门卡提前一天预约 光合仪提前一天预约 ASD ...

  6. Python第三方库之openpyxl(6)

    Python第三方库之openpyxl(6) 折线图 折线图允许在固定轴上绘制数据,它们类似于散列图,主要的区别在于,在折线图中,每个数据序列都是根据相同的值绘制的,不同的轴可以用于辅助轴,与条形图类 ...

  7. xtu数据结构 H. City Horizon

    H. City Horizon Time Limit: 2000ms Memory Limit: 65536KB 64-bit integer IO format: %lld      Java cl ...

  8. python3--__repr_和__str__会返回字符串表达形式

    __repr_和__str__会返回字符串表达形式 下一个例子是已经见过的init构造方法和add重载方法,本例也会定义返回实例的字符串表达形式的__repr__方法.字符串格式把self.data对 ...

  9. Caffe 不同版本之间layer移植方法

    本系列文章由 @yhl_leo 出品,转载请注明出处. 文章链接: http://blog.csdn.net/yhl_leo/article/details/52185521 (前两天这篇博客不小心被 ...

  10. 牛腩新闻发布系统(五):VS网站发布及常见问题

    导读:在千万个回眸中,终于看见了牛腩的归途.好吧,牛腩该整合的都整合完毕了,到了发布的时候了.这时候,不得不再次感慨那句不知道感慨了多少次的感慨:为什么,我要遭遇这么多的坎坷?下面,结合自己的情况,说 ...