CodeForces 321A Ciel and Robot(数学模拟)
来源:互联网 发布:搜一次cms官网 编辑:程序博客网 时间:2024/04/29 17:55
题目链接: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;}
0 0
- CodeForces 321A Ciel and Robot(数学模拟)
- CodeForces 321A Ciel and Robot(数学模拟 枚举答案)
- CodeForces 321A Ciel and Robot[暴力]
- CodeForces 321 A - Ciel and Robot
- CodeForces 321A Ciel and Robot
- CodeForces 321A Ciel and Robot(模拟)
- codeforces A. Ciel and Robot
- Codeforces 321A Ciel and Robot 枚举答案
- Codeforces Round 190 div.2 322C 321A Ciel and Robot
- CF 321A(Ciel and Robot-暴力枚举)
- Codeforces Round #190 (Div. 2)-C. Ciel and Robot
- codeforces 322 A Ciel and Dancing
- codeforces 327 A Ciel and Dancing
- codeforces 322A. Ciel and Dancing
- Codeforces 321B Ciel and Duel KM
- Codeforces 321E Ciel and Gondolas(DP)
- [Codeforces 321E] Ciel and Gondolas
- A. Ciel and Dancing
- hive中的增删改如何实现
- Ubuntu 12.04中下载android源代码
- 大整数相加
- 关于metasploit的一些架构目录
- 根据被选中的 radio 值,设置 checkbox 是否可用
- CodeForces 321A Ciel and Robot(数学模拟)
- rtp协议详解/rtcp协议详解
- 云计算之数据中心
- struts2 中文乱码问题
- 大整数相减
- 找规律 (1) 1, 2, 4, 7, 8, 11, 14, 16, 17, 19, 22, 26, 28, 29, 41, 44, ?
- 域渗透相关知识
- HLJUOJ1117(暴力模拟)
- 一知半解之 jstl流程控制标签