zoukankan      html  css  js  c++  java
  • 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 }
  • 相关阅读:
    Python面向对象——内置对象的功能扩展
    学术日记#学术道德与人文素养
    Python面向对象——基本继承
    SqlServer——字符串处理函数
    SqlServer——索引
    生活小问题(1)
    win7-VS2010-IIS网站的发布问题
    PhoneGap+Cordova+SenchaTouch-01-环境搭建
    sql server数字转字符串出现科学计数法
    SQLServer 重启服务后,自增1的标识列一次增长了1000(转自博问)
  • 原文地址:https://www.cnblogs.com/zllwxm123/p/7646052.html
Copyright © 2011-2022 走看看