zoukankan      html  css  js  c++  java
  • Codeforces Round #438 B. Race Against Time

    Description

    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.

    解题报告

    直接把三个针用转成时钟上的位置,也就是值域为 ([0,12]) ,double储存,然后分两种情况讨论即可,注意细节

    #include <algorithm>
    #include <iostream>
    #include <cstdlib>
    #include <cstring>
    #include <cstdio>
    #include <cmath>
    using namespace std;
    double a[5];
    void work()
    {
       double h,m,s,t1,t2;
       cin>>h>>m>>s>>t1>>t2;
       a[1]=h+m/60+s/3600;
       if(a[1]>=12)a[1]-=12;
       a[2]=m/5+s/300;
       if(a[2]>=12)a[2]-=12;
       a[3]=s/5;
       if(a[3]>=12)a[3]-=12;
       int i;
       if(t1<t2)swap(t1,t2);
       for(i=1;i<=3;i++){
          if(t1<=a[i] && a[i]<=12)break;
          if(0<=a[i] && a[i]<=t2)break;
       }
       if(i==4){
          puts("YES");
          return ;
       }
       for(i=1;i<=3;i++){
          if(t2<=a[i] && a[i]<=t1)break;
       }
       if(i==4){
          puts("YES");
          return ;
       }
       puts("NO");
    }
    
    int main()
    {
    	work();
    	return 0;
    }
    
    
  • 相关阅读:
    C#Thread学习
    C#winform拖动无边框窗体
    c#winform pictureBox使用url加载图片
    C#Async,await异步简单介绍
    C#字符串拼接的三种方式
    FreeMarker学习(宏<#macro>的使用)
    sublime text 2中Emmet8个常用的技巧
    线程通信之管道流
    程序员必懂:javaweb三大框架知识点总结
    mysql+mycat搭建稳定高可用集群,负载均衡,主备复制,读写分离
  • 原文地址:https://www.cnblogs.com/Yuzao/p/7630564.html
Copyright © 2011-2022 走看看