您的位置:首页 > 大数据 > 人工智能

Codeforces 868 B Race Against Time(水题)

2017-10-05 22:11 435 查看
题目链接

题目大意:给你一个时钟的时间 时h,分m, 秒s。在给出两个时间代表在时钟对应时刻上的点。问这两个点在不穿过时钟的针(包括时针分针秒针)的情况下能互相到达。

题目分析:把时针分针秒针形成的区域分块,能把圆最多分成3各部分。如果两个点在同一区域内说明能互相到达。

注意这里的时钟是机械钟,意味着所有指针都不是正对着刻度的。

double在所难免(还好不卡精度)。

具体操作就是把以12点为0度建立圆周。每个针对应的位置与12点形成的角度。然后分成3个区域就行了。(注意要排序)

#include<iostream>
#include<string>
#include<cstring>
#include<vector>
#include<map>
#include<algorithm>
#include<queue>
#include<set>
#include<cstdio>
#include<functional>
#include<iomanip>
#include<cmath>
#include<stack>
//#define mod 1030
#define size 3
using namespace std;
typedef long long LL;
const int maxn = (LL)1e5 + 100;
const int maxm = 50000;
const LL inf = (LL)6 * LL(1e18);
const double eps = 1e-8;
double a[4];
int main() {
double m, s;
int h, t1, t2;
while (scanf("%d", &h) == 1) {
scanf("%lf%lf%d%d", &m, &s, &t1, &t2);
h = h % 12, t1 = t1 % 12, t2 = t2 % 12;
double tmp = h, tmp1 = t1, tmp2 = t2;
a[0] = 6 * s;
a[1] = m * 6 + s / 10;
a[2] = 30 * tmp + (m + s / 60) / 2;
sort(a, a + 3);
tmp1 = 30 * tmp1, tmp2 = 30 * tmp2;
int lo1 = -1, lo2 = -1;
for (int i = 0; i < 2; i++) {
if (tmp1 >= a[i] && tmp1 <= a[i + 1]) lo1 = i;
if (tmp2 >= a[i] && tmp2 <= a[i + 1]) lo2 = i;
}
if (lo1 == -1) lo1 = 2;
if (lo2 == -1) lo2 = 2;
printf("%s\n", lo1 == lo2 ? "YES" : "NO");
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  codeforces