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

【Codeforces 868 B. Race Against Time】& 模拟

2017-10-06 11:51 507 查看
B. Race Against Time

time limit per test2 seconds

memory limit per test256 megabytes

inputstandard input

outputstandard output

Have you ever tried to explain to the coordinator, why it is eight hours to the contest and not a single problem has been prepared yet? Misha had. And this time he has a really strong excuse: he faced a space-time paradox! Space and time replaced each other.

The entire universe turned into an enormous clock face with three hands — hour, minute, and second. Time froze, and clocks now show the time h hours, m minutes, s seconds.

Last time Misha talked with the coordinator at t1 o’clock, so now he stands on the number t1 on the clock face. The contest should be ready by t2 o’clock. In the terms of paradox it means that Misha has to go to number t2 somehow. Note that he doesn’t have to move forward only: in these circumstances time has no direction.

Clock hands are very long, and Misha cannot get round them. He also cannot step over as it leads to the collapse of space-time. That is, if hour clock points 12 and Misha stands at 11 then he cannot move to 1 along the top arc. He has to follow all the way round the clock center (of course, if there are no other hands on his way).

Given the hands’ positions, t1, and t2, find if Misha can prepare the contest on time (or should we say on space?). That is, find if he can move from t1 to t2 by the clock face.

Input

Five integers h, m, s, t1, t2 (1 ≤ h ≤ 12, 0 ≤ m, s ≤ 59, 1 ≤ t1, t2 ≤ 12, t1 ≠ t2).

Misha’s position and the target time do not coincide with the position of any hand.

Output

Print “YES” (quotes for clarity), if Misha can prepare the contest on time, and “NO” otherwise.

You can print each character either upper- or lowercase (“YeS” and “yes” are valid when the answer is “YES”).

Examples

input

12 30 45 3 11

output

NO

input

12 0 1 12 1

output

YES

input

3 47 0 4 9

output

YES

Note

The three examples are shown on the pictures below from left to right. The starting position of Misha is shown with green, the ending position is shown with pink. Note that the positions of the hands on the pictures are not exact, but are close to the exact and the answer is the same.

题意 : 能否从 t1 到达 t2,顺时针或逆时针,中间的时针,分针,秒针会挡着路

思路 : 顺 || 逆时针各模拟一下

AC代码:

#include<cstdio>
#include<cmath>
#include<deque>
#include<queue>
#include<vector>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAX = 1e5 + 10;
const int INF = 1e9 + 7;
typedef long long LL;
bool sf(double x,double y,double z){
if(z <= x || z >= y)
return true;
return false;
}
int main()
{
double h,m,s,h1,h2;
scanf("%lf %lf %lf %lf %lf",&h,&m,&s,&h1,&h2);
m += s / 60,h += m / 60;
double ma = m / 5,ms = s / 5;
if(h1 > h2) swap(h1,h2);
if(sf(h1,h2,h) && sf(h1,h2,ma) && sf(h1,h2,ms)){
puts("YES");
return 0;
}
if(h1 < h2) h1 += 12;
double x = h + 12,y = ma + 12,z = ms + 12;
if(sf(h2,h1,x) && sf(h2,h1,y) && sf(h2,h1,z) && sf(h2,h1,h) && sf(h2,h1,ma) && sf(h2,h1,ms)){
puts("YES");
return 0;
}
puts("NO");
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Codeforces 868B 模拟 Race