• 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 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 #include <bits/stdc++.h>
     2 #define N 432000
     3 using namespace std;
     4 int h,m,s,t1,t2;
     5 int k[N];
     6 int main(){
     7   cin>>h>>m>>s>>t1>>t2;
     8   bool prime=true;
     9   bool flag=true;
    10   t1=t1%12,t2=t2%12,h=h%12;
    11   int x=s*60*12,y=m*60*12+s*12,z=h*3600+m*60+s;
    12   k[x]=k[y]=k[z]=1;
    13   t1=t1*3600; t2=t2*3600;
    14   int xx=min(t1,t2);
    15   int yy=max(t1,t2);
    16   for(int i=xx;i<=yy;i++){
    17     if(k[i]==1){
    18       prime=false;
    19       break;
    20     }
    21   }
    22   if(prime){
    23     cout<<"YES"<<endl;
    24   }else{
    25     for(int i=0;i<=xx;i++){
    26       if(k[i]==1){
    27         flag=false;
    28         break;
    29       }
    30     }
    31     if(flag){
    32       for(int i=yy;i<N;i++){
    33         if(k[i]==1){
    34           flag=false;
    35           break;
    36         }
    37       }
    38     }
    39     if(flag){
    40       cout<<"YES"<<endl;
    41     }else{
    42       cout<<"NO"<<endl;
    43     }
    44   }
    45   return 0;
    46 }
  • 相关阅读:
    UOJ 347(洛谷4220) 【WC2018】通道——随机化
    bzoj 5006(洛谷 4547) [THUWC2017]Bipartite 随机二分图——期望DP
    bzoj 5020(洛谷4546) [THUWC 2017]在美妙的数学王国中畅游——LCT+泰勒展开
    bzoj 4006 [JLOI2015]管道连接——斯坦纳树
    洛谷4294 [WC2008]游览计划——斯坦纳树
    CF 757 E Bash Plays with Functions —— 积性函数与质因数分解
    洛谷 P2444 [ POI 2000 ] 病毒 —— AC自动机+dfs
    洛谷 P1072 Hankson 的趣味题 —— 质因数分解
    洛谷 P1071 潜伏者 —— 模拟
    洛谷 P1541 乌龟棋 —— DP
  • 原文地址:https://www.cnblogs.com/zllwxm123/p/7646052.html
Copyright © 2020-2023  润新知