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;
    }
    
    
  • 相关阅读:
    toggle
    Java 运算符
    Java 修饰符
    Java 变量类型
    java对象和类
    java基础笔记
    Java添加事件的几种方式(转载了codebrother的文章)
    mybatis中的#和$的区别?
    为什么java里面经常作List判断的时候,既要判断list不为null,又要判断size>0呢,岂不是多此一举吗?
    发送邮件功能 Service 层
  • 原文地址:https://www.cnblogs.com/Yuzao/p/7630564.html
Copyright © 2011-2022 走看看