Codeforces Round 190 div.2 322C 321A Ciel and Robot
来源:互联网 发布:淘宝"钓鱼 编辑:程序博客网 时间:2024/05/16 10:17
唔。。。这题是数学题。
比赛时做出来,但题意理解错了,以为只要判断那点是不是在线上就行了,发现过不了样例就没提交。
思路:记录每一步的偏移,假设那点是在路径上的某步,然后回推出那一个周期的第一步,判断是不是在线上就行了。
本来用斜率做,没考虑斜率不存在的情况。
重新写了一遍,过了前十个样例。但是在追加的-1 -1 UR卡住了。
三鲜大神说: kx + b = y,判断整除就可以了。(orz)
于是想了一下,开始考虑整除,写了个判断的函数来判断就行了。(蒻菜只能写出又长又臭的判断)
代码:
#include <cstdio>#include <cstring>int x = 0, y = 0, pos[101][2] = {0};bool judge(int px, int py) { if (x == 0 && y != 0) if (px == 0 && py % y == 0 && py / y >= 0) return true; else return false; if (y == 0 && x != 0) if (py == 0 && px % x == 0 && px / x >= 0) return true; else return false; if (x == 0 && y == 0) if (px == 0 && py == 0) return true; else return false; if (x != 0 && y != 0) if (py == px / x * y && px % x == 0 && px / x >= 0) return true; else return false;}//boolint main() { int a, b; char op[101]; scanf("%d%d%s", &a, &b, op); if (a == 0 && b == 0) { printf("Yes\n"); return 0; } for (int i = 0; i < strlen(op); i++) { switch (op[i]) { case 'U': y++; break; case 'D': y--; break; case 'L': x--; break; case 'R': x++; break; } pos[i][0] = x; pos[i][1] = y; }//for for (int i = 0; i < strlen(op); i++) if (judge(a - pos[i][0], b - pos[i][1])) { printf("Yes\n"); return 0; }//if printf("No\n"); return 0;}
以后要争取在比赛时做出C及后面的题目。。。
- Codeforces Round 190 div.2 322C 321A Ciel and Robot
- Codeforces Round #190 (Div. 2)-C. Ciel and Robot
- Codeforces Round #190 (Div. 2)---A. Ciel and Dancing
- CodeForces 321A Ciel and Robot[暴力]
- CodeForces 321 A - Ciel and Robot
- CodeForces 321A Ciel and Robot
- codeforces A. Ciel and Robot
- CodeForces 321A Ciel and Robot(数学模拟)
- Codeforces 321A Ciel and Robot 枚举答案
- CodeForces 321A Ciel and Robot(数学模拟 枚举答案)
- CodeForces 321A Ciel and Robot(模拟)
- Codeforces Round #206 (Div. 2) C - Vasya and Robot
- Codeforces Round #206 (Div. 2) C. Vasya and Robot
- Codeforces Round #206 (Div. 2) C-Vasya and Robot
- 想法题——Codeforces Round #190 (Div. 2)——B. Ciel and Flowers
- Codeforces Round #206 (Div. 1) A. Vasya and Robot
- Codeforces 322C Ciel and Robot【思维+模拟】细节很多= =
- codeforces 322 A Ciel and Dancing
- Libcurl与MASM32汇编
- 尝鲜Jekyll
- UUID与GUID
- js 动态行(增/删)示例
- 黑马程序员:Java基础总结----子接口 List<E>及其实现类
- Codeforces Round 190 div.2 322C 321A Ciel and Robot
- 【rmzt推荐:精美桌面主题 】
- 黑马程序员:Java基础总结----子接口 set<E>及其实现类
- 何时会发生db file sequential read等待事件?
- org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'xxx' in
- window.opener无效与《java web 开发实战经典》
- Python strip lstrip rstrip使用方
- 深入学习才有进步
- 仿CSDN Blog返回页面顶部功能