题目链接: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. 【转发】【linux】【php】centos 编译php常见错误

    configure: error: xml2-config not found. Please check your libxml2 installation. yum install libxml2 ...

  2. Python模块(一)(常用模块)

    1. 简单了解模块 写的每一个py文件都是一个模块. 还有一些我们一直在使用的模块 buildins 内置模块. print, input random 主要是和随机相关的内容 random()    ...

  3. HDU 6447

    YJJ's Salesman Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)To ...

  4. centos 装 android studio

    一.安装前的准备 1.1.如果你还没有安装ubuntu 14.04 LTS系统,请参考下面的文章安装 http://blog.csdn.net/lsyz0021/article/details/521 ...

  5. git (unable to update local ref )

    https://stackoverflow.com/questions/2998832/git-pull-fails-unable-to-resolve-reference-unable-to-upd ...

  6. H5系列之地理位置(必知必会)

    H5之地理位置必知必会     [02]概念   规范地址:http://www.w3.org/TR/geolocation-API/     HTML5 Geolocation(地理定位)用于定位用 ...

  7. 性能学习笔记之四--事务,思考时间,检查点,集合点和手写lr接口

    一.事物,思考时间,检查点,集合点 1.事务 lr里面的事物是lr运行脚本的基础.lr里面 要测试的三个维度都以事物为单位,所以一定要有事物.事务的概念贯穿loadrunner的使用,比如我们说的响应 ...

  8. [BZOJ1579] [Usaco2009 Feb]Revamping Trails 道路升级(分层图最短路 + 堆优化dijk)

    传送门 dis[i][j]表示第i个点,更新了j次的最短路 此题不良心,卡spfa #include <queue> #include <cstdio> #include &l ...

  9. win10安装virtualbox发生严重错误

    转载自:http://blog.csdn.net/ljw124213/article/details/50545101 Windows 10 系统在安装VirtualBox即将完毕时,突然回退,提示错 ...

  10. COdevs 1074 食物链

    1074 食物链 2001年NOI全国竞赛  时间限制: 3 s 空间限制: 64000 KB 题目等级 : 钻石 Diamond 题目描述 Description 动物王国中有三类动物 A,B,C, ...