题目链接: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 1463 C. Busy Robot 模拟

    CodeForces 1463 C. Busy Robot 模拟 题目大意: 有一个一维坐标轴,在最初时刻有个机器人位于坐标 0 0 0 位置,有 n n n 个命令,对于每一个命令在 t i t_i ...

  2. Ciel and Robot CodeForces - 322C

    Fox Ciel has a robot on a 2D plane. Initially it is located in (0, 0). Fox Ciel code a command to it ...

  3. cf Educational Codeforces Round 133 C. Robot in a Hallway

    原题: There is a grid, consisting of 2 rows and m columns. The rows are numbered from 1 to 2 from top ...

  4. android studio生命周期代码,Android Studio 单刷《第一行代码》系列 06 —— Fragment 生命周期...

    前情提要(Previously) 本系列将使用 Android Studio 将<第一行代码>(书中讲解案例使用Eclipse)刷一遍,旨在为想入坑 Android 开发,并选择 Andr ...

  5. 【codeforces 752C】Santa Claus and Robot

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  6. Codeforces 1196C Robot Breakout

    https://codeforces.com/contest/1196/problem/C 题解:思维+交集 /* *@Author: STZG *@Language: C++ */ #include ...

  7. Yet Another Walking Robot CodeForces - 1296C

    There is a robot on a coordinate plane. Initially, the robot is located at the point (0,0)(0,0). Its ...

  8. Codeforces Round #753 (Div. 3)E. Robot on the Board 1

    问题翻译: The robot is located on a checkered rectangular(直角 的) board of size n×m (n rows, m columns). T ...

  9. Codeforces Round #190 (Div. 1): E. Ciel and Gondolas(决策单调性DP+wqs二分)

    E. Ciel and Gondolas 题意: bzoj5311:https://www.lydsy.com/JudgeOnline/problem.php?id=5311 同一道题目,但是bzoj ...

最新文章

  1. 彭博社 : 中国稀土——美欧的苦恼
  2. Machine Learning:如何选择机器学习算法?
  3. mysql和mongodb替换字段中某字符
  4. 为什么要在密码里加点“盐”
  5. 安装华为鸿蒙,魅族选择与鸿蒙合作,华为这下要成了?
  6. Python编程教程:面向对象之高级特性!
  7. 【分布式】缓存穿透、缓存雪崩,缓存击穿解决方案
  8. topcoder srm 686 div1 -3
  9. 单元测试自动生成测试用例
  10. 如何设置快速启动栏 win7 快速启动栏 快速启动栏不见了
  11. 心知天气api PHP,心知天气API的应用实例
  12. 算法——连续性后处理(把26邻域连续的变成6邻域连续的)
  13. CleanMyMac2023一键清除垃圾缓存和恶意广告插件 时刻保持Mac畅快运行
  14. SpringBoot 如何进行限流?老鸟们都这么玩的!
  15. 科普大佬说 | 港大黄凯斌老师带你解锁黑客帝国与6G的关系
  16. java记事本编程工作原理_Java文件(io)编程之记事本开发详解
  17. 程序员写博客的意义何在?为什么推荐程序员写个人博客?
  18. nodejs express摸爬滚打篇:express中使用mysql
  19. Springboot足球运动员训练计划管理系统的设计与实现 毕业设计-附源码281444
  20. mallet java_Mallet:自然语言处理工具包

热门文章

  1. 获取用户精准地理位置信息(百度地图)
  2. Linux snmp
  3. nodemailer实现node发送邮件
  4. git创建与管理远程分支
  5. SQL转换函数to_char/to_date/to_number
  6. MySQL查询优化-explain
  7. NTFS磁盘的安全与管理
  8. TABCTL32.OCX 文件
  9. 7.10.7740.16
  10. Spread for Windows Forms快速入门(2)---设置Spread表单