Codeforces Round #438 B. Race Against Time 思路很重要

在一次时空悖论中,Misha需要在一个巨大的时钟表面上从一个时间点移动到另一个时间点以完成竞赛的准备工作。时钟有三根指针,时间停滞在特定的位置。Misha不能穿越指针,必须绕过它们。任务是在给定指针位置的情况下,判断Misha是否能从初始时间点到达目标时间点。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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").


某位大神的代码,基本思路和我一样,但是判断方法我真的麻烦到爆炸,最后错了一组数据.哎

这里是统计t1到t2通过了几个指针。  如果通过0个或者通过3个都是可以的。因为如果通过三个的话,反向就是0个。

一定不要for按个枚举..各种的错误..

#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <queue>
#include <vector>
using namespace std;
int a,b,c,d,e;
int f[100];
int main()
{
    scanf("%d%d%d%d%d",&a,&b,&c,&d,&e);
    a*=5,d*=5,e*=5;
    a%=60;
    d%=60;
    e%=60;
    f[a]++;
    f[b]++;
    f[c]++;
    if(d>e) swap(d,e);
    int ans=0;
    for(int i=d;i<e;i++)ans+=f[i];
    if(ans%3==0)puts("YES");
    else puts("NO");
return 0;
}



评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值