题目链接: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. **没有规则可以创建“XXX”需要的目标“XXX”问题的解决方案

    一.现象 我将之前Redhat9.0编译好的uboot,转到ubuntu12.04环境.在ubuntu环境下对 uboot重新编译提示错误.编译过程如下: root@hailin-virtual-ma ...

  2. Web框架之Django_08 重要组件(form组件、cookie和session组件)

    摘要: form组件 cookie组件 session组件 一.form组件 form介绍我们之前在html页面中利用form表单向后端提交数据时候,都需要对用户的输入进行校验,比如校验用户是否输入正 ...

  3. pymongo的简单使用

    pymongo的使用 首先安装: pip install pymongo 安装好了使用 import pymongo # 链接mongodb,得到一个mongoclient的客户端对象 client ...

  4. js--如何判别 null undefined

    收集资料如下判断: 1.判断undefined: ? 1 2 3 4 var tmp = undefined; if (typeof(tmp) == "undefined"){ a ...

  5. Python小课题练习作业

    作业一: 利用*字典*输出目录,可以选择目录进入,可以回退.退出! #conding:utf8 menu = {'北京':{'昌平':{'沙河':{'昌平妇幼',}},'海淀':{'海淀一区':{'海 ...

  6. appium+python自动化-adb shell按键操作(input keyevent)

    前言 接着上篇介绍input里面的按键操作keyevent事件,发送手机上常用的一些按键操作 keyevent 1.keyevent事件有一张对应的表,可以直接发送对应的数字,也可以方式字符串,如下两 ...

  7. Appium切换webview时候报chromedriver版本问题

    前言 用appium切换webview的时候报chrome和chromedriver版本的问题:session not created exception: Chrome version must b ...

  8. 对于一棵二叉树,请设计一个算法,创建含有某一深度上所有结点的链表。 给定二叉树的根结点指针TreeNode* root,以及链表上结点的深度,请返回一个链表ListNode,代表该深度上所有结点的值,请按树上从左往右的顺序链接,保证深度不超过树的高度,树上结点的值为非负整数且不超过100000。

    /* struct TreeNode { int val; struct TreeNode *left; struct TreeNode *right; TreeNode(int x) : val(x ...

  9. 信安实验-RC4加密算法

    RC4加密算法 算法具体就不介绍了,应信安老师要求整理及掌握. #include<bits/stdc++.h> using namespace std; const int N=256; ...

  10. 如何诊断RAC系统中的'gc cr multi block request'?

    'gc cr multi block request' 是RAC数据库上比较常见的一种等待事件,在RAC 上进行全表扫描(Full Table Scan)或者全索引扫描(Index Fast Full ...