题目链接: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. 【php】 检测 ie ie11 edge浏览器

    来源 php.net 官网评论截取 -- Declan kelly Please note that Internet Explorer 11 no longer contains MSIE in i ...

  2. python 基础知识汇总—— if else while continue

    1.if 语句 什么是if语句?if语句用来干什么的? if语句说通俗点,就是判断,如果判断条件为真,那么就执行语句,就像我们生活中例子,如果你饿了,判断为真,就要吃饭,于是你就会执行吃饭这个动作,如 ...

  3. Python基础知识-day2

    格式化输出 %占位符,s字符串,d 数字, 表示%  用%% name = input("请输入姓名: ") age = input("请输入年龄: ") he ...

  4. js--进阶知识点

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  5. 【LeetCode】Design Linked List(设计链表)

    这道题是LeetCode里的第707到题.这是在学习链表时碰见的. 题目要求: 设计链表的实现.您可以选择使用单链表或双链表.单链表中的节点应该具有两个属性:val 和 next.val 是当前节点的 ...

  6. Brownie Slicing(二分枚举答案)

    描述 Bessie has baked a rectangular brownie that can be thought of as an RxC grid (1 <= R <= 500 ...

  7. 【java 基础 9】原来我从没有了解过String类

    导读:这两天没有做项目,然后就想着把之前在项目中用到过的东西总结总结.记得之前做今日开讲项目时,在比较学生学号的时候,我最开始用的是"==",但是,实践证明,这个玩意儿吧,总是很奇 ...

  8. 算法复习——求最长不下降序列长度(dp算法)

    题目: 题目背景 161114-练习-DAY1-AHSDFZ T2 题目描述 有 N 辆列车,标记为 1,2,3,…,N.它们按照一定的次序进站,站台共有 K 个轨道,轨道遵从先进先出的原则.列车进入 ...

  9. Eclipse 语言文件下载地址

    http://www.eclipse.org/babel/downloads.php 更改配色: 安装新软件: http://eclipse-color-theme.github.com/update

  10. WAMP本地环境升级php版本

    !!!本次测试未完全成功,仅供提供经验. (1)下载php最新版本 http://windows.php.net/download/ (2)解压放到wamp/bin/php目录下 (3) 从已存在的p ...