Codeforces Round 190 div.2 322C 321A Ciel and Robot
唔。。。这题是数学题。
比赛时做出来,但题意理解错了,以为只要判断那点是不是在线上就行了,发现过不了样例就没提交。
思路:记录每一步的偏移,假设那点是在路径上的某步,然后回推出那一个周期的第一步,判断是不是在线上就行了。
本来用斜率做,没考虑斜率不存在的情况。
重新写了一遍,过了前十个样例。但是在追加的-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;
}//bool
int 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) E
http://codeforces.com/contest/322/problem/E E. Ciel the Commander time limit per test 1 second memor ...
- Codeforces Round #190 (Div. 1 + Div. 2)
A. Ciel and Dancing 模拟. B. Ciel and Flowers 混合类型的数量只能为0.1.2,否则3个可以分成各种类型各自合成. C. Ciel and Robot 考虑一组 ...
- Codeforces Round #190 (Div. 2) E. Ciel the Commander 点分治
E. Ciel the Commander Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.codeforces.com/contest ...
- Codeforces Round #190 (Div. 2) B. Ciel and Flowers
链接:http://codeforces.com/contest/322/problem/B 这题做错了.没考虑周全. #include <cstdio> #include <cst ...
- Codeforces Round #190 DIV.2 A. Ciel and Dancing
#include <cstdio> #include <iostream> #include <vector> using namespace std; int m ...
- Codeforces Round #190 (Div. 2).D
一道贪心题. 可以分两种情况 1 .是没有把对面的牌全打败,那么只要用最大的可能去打攻击状态的牌. 2. 是将对面的牌全打败,那么只要保证打对面防守状态的花费最小,就可以保证最后的结果最大 两种情况下 ...
- Codeforces Round #190 (Div. 2) 水果俩水题
后天考试,今天做题,我真佩服自己... 这次又只A俩水题... orz各路神犇... 话说这次模拟题挺多... 半个多小时把前面俩水题做完,然后卡C,和往常一样,题目看懂做不出来... A: 算是模拟 ...
- [置顶] Codeforces Round #190 (Div. 2)(完全)
好久没有写博客了,一直找不到有意义的题可以写,这次也不算多么有意义,只是今天是比较空的一天,趁这个时候写一写. A. B. 有一点贪心,先把每个拿去3的倍数,余下0或1或2,然后三个一起拿. 对于以上 ...
- Codeforces Round #389 Div.2 C. Santa Claus and Robot
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...
随机推荐
- Linux重复执行上条命令
Linux系统下Shell重复执行上条命令的 4 种方法: 1.使用上方向键,并回车执行.2.按 !! 并回车执行.3.输入 !-1 并回车执行.4.按 Ctrl+P 并回车执行.
- vs2012不能打开项目解决办法
只要卸载这两个不定就能解决问题.
- J2EE开发常用开源框架技术(转)
1持久层:1)Hibernate这个不用介绍了,用的很频繁,用的比较多的是映射,包括继承映射和父子表映射对 于DAO在这里介绍个在它基础上开发的包bba96,目前最新版本是bba96 2.0它对Hib ...
- cloudera hbase集群简单思路
文章copy link:http://cloudera.iteye.com/blog/889468 链接所有者保留所有权! http://www.csdn.net/article/2013-05-10 ...
- 栈的简单应用 HDU 1022 http://acm.hdu.edu.cn/showproblem.php?pid=1022
#include<stdio.h> #include<stack> #include<string.h> #define N 20 using namespace ...
- CentOS 下安装操作Memcached
Memcached 是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载.它通过在内存中缓存数据和对象来减少读取数据库的次数,从而提高动态.数据库驱动网站的速度.Memcached ...
- cocos2d-x CCListView
转自:http://blog.csdn.net/onerain88/article/details/7641126 cocos2d-x 2.0 版更新了,把opengl 1.1 替换为opengl 2 ...
- POI Excel导出样式设置
HSSFSheet sheet = workbook.createSheet("sheetName"); //创建sheet sheet.setVerticallyCente ...
- 从hello-world 开始 <contiki学习之四>
按照contiki 官方给出的example下的例子之hello world来说,所有的工程里面都有一个唯一的Makefile.然后这个Makefile会去调用其他makefile文件.于是,一切就从 ...
- java泛型的讲解
java泛型 什么是泛型? 泛型(Generic type 或者 generics)是对 Java 语言的类型系统的一种扩展,以支持创建可以按类型进行参数化的类.可以把类型参数看作是使用参数化类型时指 ...