CodeFroces Round 438 B.Race Against Time(模拟)

来源:互联网 发布:ios与安卓的区别 知乎 编辑:程序博客网 时间:2024/06/10 19:06

题意:给出时间,那么钟上的三个指针就确定位置,现在要从t1到t2,中途不可以穿越指针,问是否可行。

解法:当时想的是既然是小时之间的,那么我只需要把小时之间的给标记了即可。但是这样写会有反例。所以应该把这个钟扩大12*60倍。然后对应的标记上每个指针的位置,然后正反for一遍即可。

代码如下:

#include<iostream>#include<cstdio>#include<vector>#include<queue>#include<utility>#include<stack>#include<algorithm>#include<cstring>#include<string>#include<cmath>#include<set>#include<map>using namespace std;bool flag[60005];int main() {#ifndef ONLINE_JUDGE//freopen("in.txt", "r", stdin);//    freopen("out.txt", "w", stdout);#endifint h, m, s, t1, t2;scanf("%d%d%d%d%d", &h, &m, &s, &t1, &t2);if(h == 12)h = 0;if(t1 == 12)t1 = 0;if(t2 == 12)t2 = 0;flag[h * 3600 + m * 60 + s] = 1;flag[m * 60 * 12 + s] = 1;flag[s * 60 * 12] = 1;t1 *= 3600;t2 *= 3600;bool key = 0;if(t1 == t2)key = 1;for(int i = t1; ; i++) {if(i == t2)key = 1;if(flag[i])break;if(i >= 60000)i = -1;}for(int i = t1; ; i--) {if(i == t2)key = 1;if(flag[i]) break;if(i <= 0)i = 60000;}if(key == 1)printf("YES\n");elseprintf("NO\n");return 0;}


原创粉丝点击