codeforces 868B Race Against Time(思维)

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 hmst1, 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.

题意:现在有一个表,给出小时h,分钟m以及秒钟s。然后给出两个点(整点),是否可以不跨过表的指针,从一个点走到另一个点。

思路:我们可以将分钟和秒钟所指的点换算出来。如果秒不为0,那么我们可以认为分钟多走了0.5格(因为如果秒种不为0,那么分钟实际上不会正指向某一个值,而是有稍微的偏移,又因为给出的点是整点,那么如果有偏移的话,可以直接认为多走了0.5格,对于小时来说,同样成立)。然后我们只需要分情况讨论就可以可。

#include "iostream"
using namespace std;
int main()
{
    int h,m,s,t1,t2,t;
    double H,M,S;
    cin>>h>>m>>s>>t1>>t2;
    H=h;
    M=0;
    if(s!=0) M=0.5;
    S=s/5;
    if(s%5!=0) S+=0.5;
    if(m!=0||M!=0) H+=0.5;
    if(m%5!=0) M=0.5;
    M+=m/5;
    if(t1>t2) t=t1,t1=t2,t2=t;
    if((H>t1&&H<t2||M>t1&&M<t2||S>t1&&S<t2)&&(H>t1&&H>t2||M>t1&&M>t2||S>t1&&S>t2||H<t1&&H<t2||M<t1&&M<t2||S<t1&&S<t2))
        cout<<"NO"<<endl;
    else cout<<"YES"<<endl;
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_41874469/article/details/81101125
今日推荐