zoukankan      html  css  js  c++  java
  • codeforces 868B Race Against Time

    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.

    题目大意:

    给定一个时间,在不经过时分秒针的情况下,从第t1点到t2点

    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.

     模拟,但有细节

    算出double类型的详细时间,把针所指的都统一成60格一周的单位,即把小时×5

    再把查询统一

    接下来破环成链,模拟判断就行了

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<algorithm>
     4 #include<cstring>
     5 using namespace std;
     6 double h,m,s,t1,t2,h2,m2,s2;
     7 int flag1,flag2;
     8 int main()
     9 {
    10   cin>>h>>m>>s>>t1>>t2;
    11   t1*=5.0;t2*=5.0;
    12   m=m+s/60;
    13   if (m>=60.0) m-=60.0;
    14   h=h*5+m/12;
    15   if (h>=60.0) h-=60.0;
    16   s2=60.0+s;
    17   m2=60.0+m;
    18   h2=60.0+h;
    19   if (t1>t2) swap(t1,t2);
    20   flag1=1;
    21   if ((t1<s&&s<t2)||(t1<s2&&s2<t2)||(t1<m&&m<t2)||(t1<m2&&m2<t2)||(t1<h&&h<t2)||(t1<h2&&h2<t2))
    22     {
    23       flag1=0;
    24     }
    25   t1+=60;
    26   if (t1>t2) swap(t1,t2);
    27   flag2=1;
    28   if ((t1<s&&s<t2)||(t1<s2&&s2<t2)||(t1<m&&m<t2)||(t1<m2&&m2<t2)||(t1<h&&h<t2)||(t1<h2&&h2<t2))
    29     {
    30       flag2=0;
    31     }
    32   if (flag1||flag2) cout<<"YES
    ";
    33   else cout<<"NO
    ";
    34 }
  • 相关阅读:
    24.Spring-Boot-Actuator与Spring-Security整合应用
    Spring Boot 和 Spring 到底有啥区别?用了这么久,你知道吗?
    一文,5 分钟搞明白 MySQL 是如何利用索引的!
    大厂面试必问的Spring全家桶 4 大开源框架,思维脑图全总结,终于出来了
    这些SQL错误用法,如果经常犯,说明你的水平还很low...
    新技能 MyBatis 千万数据表,快速分页!
    牛逼!在IDEA里搞Spring Boot Mybatis反向工程,太爽咯~
    有了 HTTP 协议,为什么还要 RPC 协议,两者有什么区别?
    把 Spring Cloud 给拆了!详解每个组件的作用,值得收藏!
    27个阿里 Java 开源项目,值得收藏!
  • 原文地址:https://www.cnblogs.com/Y-E-T-I/p/7629857.html
Copyright © 2011-2022 走看看