Codeforce Race Against Time

来源:互联网 发布:淘宝女运动套装大吗 编辑:程序博客网 时间:2024/06/03 10:09
 Race Against Time

time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard 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 areally 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 timeh hours, m minutes,s seconds.

Last time Misha talked with the coordinator at t1 o'clock, so now he stands on the numbert1 on the clock face. The contest should be ready byt2 o'clock. In the terms of paradox it means that Misha has to go to numbert2 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 sayon space?). That is, find if he can move fromt1 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.






题意:
输入时、分、秒和两个表示小时的点,问时针、分针和秒针分成的三个区间有没有使得两个点在同一个区间。

思路:
首先把三个针指的数变成表上的数(小数),从小到大排序
对于1~12的区间正常判断
对于最大值和最小值,若在他们之间则是“YES”

代码:
#include<iostream>#include<cstdio>#include<cmath>#include<string>#include<algorithm>using namespace std;bool pd(double l,double r,double a,double b){    if( (a>=l&&a<=r) && (b>=l&&b<=r))return 1;    return 0;}int main(){    double h,s,m,a,b;    cin>>h>>s>>m>>a>>b;    if(a>b)swap(a,b);    if(s!=0 || m!=0)        h+=0.1;        s=s*1.0/60*12;    if(m!=0)        s+=0.1;        m=m*1.0/60*12;        double p[5]={h,s,m};    sort(p,p+3);        int f=0;    for(int i=0;i<2;i++)        if(pd(p[i],p[i+1],a,b))            f=1;        if( (a<=p[0]&&b>=p[2]) || (a>=p[2] && b>=p[2]) || (a<=p[0]&& b<=p[0]))        f=1;        cout<< (f==1?"YES":"NO") <<endl;    return 0;}



原创粉丝点击