Codeforces Round #438 (Div. 1 + Div. 2 combined) B. Race Against Time(模拟)

来源:互联网 发布:python re.match 编辑:程序博客网 时间:2024/06/04 19:24

B. 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 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 hmst1t2 (1 ≤ h ≤ 120 ≤ m, s ≤ 591 ≤ t1, t2 ≤ 12t1 ≠ 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.




题解:

还比较有意思的一题,就是给出时分秒,给出人要走的两个时间点(任何一个都可以作为起点和终点,可以顺时针也可以逆时针),问是否可以顺利走完(不碰到时分秒的针)

思路:

我开了120的数组,每2位表示一个刻度(为了处理不是整点的问题),如果分秒都为0,则时针的位置为h*10,否则随便加一个1-9的数字表示不是整点,同理如果秒为0,分针的位置为m*2,否则就为m*2+1,秒针就直接s*2,然后顺时针搞一遍,可以就输出yes,不行就逆时针搞一遍,可以就输出yes,否则就是no

暂时ac代码:

#include<iostream>#include<cstring>#include<stdio.h>#include<math.h>#include<string>#include<stdio.h>#include<queue>#include<stack>#include<map>#include<vector>#include<deque>#include<algorithm>#define ll long long#define INF 1008611111#define M (t[k].l+t[k].r)/2#define lson k*2#define rson k*2+1using namespace std;int vis[125];int main(){    int t1,t2,h,m,s,tag=1,st,ed,i;    scanf("%d%d%d%d%d",&h,&m,&s,&t1,&t2);    memset(vis,0,sizeof(vis));    if(h==12)        h=0;    if(m==0&&s==0)        vis[h*10]=1;    else        vis[h*10+5]=1;    if(s==0)        vis[m*2]=1;    else        vis[m*2+1]=1;    vis[s*2]=1;    if(t1>t2)        swap(t1,t2);    st=t1*10;    ed=t2*10;    for(i=st;i<=ed;i++)    {        if(vis[i])        {            tag=0;            break;        }    }    if(tag)    {        printf("YES\n");        return 0;    }    int flag=1;    for(i=ed;i<=120;i++)    {        if(vis[i])        {            flag=0;            break;        }    }    for(i=0;i<=st;i++)    {        if(vis[i])        {            flag=0;            break;        }    }    if(flag)        printf("YES\n");    else        printf("NO\n");    return 0;}



阅读全文
0 0
原创粉丝点击