Codeforces Round #438 - B. Race Against Time

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.




题意:

给你一个钟的时间,即给你指针的位置,给你t1时和t2时,让你判断从前到后或者从后到前能不能不碰到指针。


POINT:

把12个刻度之间都增加一个刻度,这样指针如果偏了,就直接当作指在中间。因为判断是从一个正数到另一个正数,所以只要知道有没有偏就行了。


#include <iostream>
#include <string.h>
#include <stdio.h>
#include <vector>
#include <algorithm>
using namespace std;
#define LL long long
const int maxn = 100100;
int flag[maxn];
int main()
{
    int h,m,s,t1,t2;
    cin>>h>>m>>s>>t1>>t2;
    if(h==12) h=0;
    if(t1==12) t1=0;
    if(t2==12) t2=0;
    if(m!=0||s!=0)
        flag[h*2+1]++;
    else
        flag[h*2]++;
    int cnt=m/5;
    if(m%5==0&&s==0)
        flag[cnt*2]++;
    else
        flag[cnt*2+1]++;
    cnt=s/5;
    if(s%5==0)
        flag[cnt*2]++;
    else
        flag[cnt*2+1]++;
    t1=t1*2;
    t2=t2*2;
    if(t1>t2) swap(t1, t2);
    int ans=0;
    for(int i=t1;i<=t2;i++){
        ans+=flag[i];
    }
    if(ans==0||ans==3){
        printf("YES\n");
    }
    else
        printf("NO\n");
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值