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;
    }
    
    
  • 相关阅读:
    JS正则表达式验证账号、手机号、电话和邮箱
    Asp.Net Mvc导出Excel
    后台截取姓名,只留姓名字带*号覆盖
    后台根据身份证号码截取性别和出生日期
    后台传个变量,前台页面显示对应的中文
    第一次封装JS文件之滚动条
    阿里巴巴17校招测试题目(Jquery解法)
    阿里巴巴17实习生招聘编程题目(JavaScript解法)
    SofewareTesting hw3
    PHP之login
  • 原文地址:https://www.cnblogs.com/Yuzao/p/7630564.html
Copyright © 2011-2022 走看看