• 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;
    }
    
    
  • 相关阅读:
    计算机组成原理_存储器
    常用CMD命令
    swiper及其父级隐藏之后轮播失效问题
    canvas生成海报
    移动端h5 实现多个音频播放
    vuex的一些学习
    关于H5的一些杂思细想(一)
    vue Error: No PostCSS Config found in
    vue路由传参的三种方式区别(params,query)
    vue-cli+mock.js+axios模拟前后台数据交互
  • 原文地址:https://www.cnblogs.com/Yuzao/p/7630564.html
Copyright © 2020-2023  润新知