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

    题意: 这题题意看了我好久,意思就是给你时针,分针,秒针,再给你一个起点和终点,起点和终点均为小于12的整数,问你能不能在钟上

         从起点走到终点,而不越过指针。

    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

    思路:就是判断一下有没有越过指针,要考虑很多种特殊情况,有点烦,后来才发现原来很简单的,判断一下正着走行不行,再判断一下反
        着走行不行,反着走时,如果指针所指大于终点所指,就加上12。比如,终点在10,如果指针在11就不用加,但是如果在1,就要变
        成13。

    代码:
    #include<iostream>
    #include<string.h>
    using namespace std;
    int h,t1,t2;
    double m,s;

    int main(){
        cin>>h>>m>>s>>t1>>t2;
        m/=5;
        s/=5;
        int mi=min(t1,t2),ma=max(t1,t2);
        bool f=1;
        for(int i=mi+1;i<=ma;i++){
            if((i-1<=h&&i>h)||(i-1<=m&&i>m)||(i-1<=s&&i>s)){
                f=0;
                break;
            }
        }
        if(f==0)f=1;
        else {
            cout<<"YES"<<endl;
            return 0;
        }
        if(h<ma)h+=12;
        if(m<ma)m+=12;
        if(s<ma)s+=12;
        for(int i=ma+1;i<=mi+12;i++){
            if((i-1<=h&&i>h)||(i-1<=m&&i>m)||(i-1<=s&&i>s)){
                f=0;
                break;
                
            }
        }
        if(f)cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
        return 0;
    }
     

  • 相关阅读:
    apache的用户认证
    Apache的配置文件
    AH00052: child pid 25043 exit signal Segmentation fault (11)
    Apache的工作模式
    apache的目录别名
    RAID的几种级别
    网络服务--NFS服务
    MySQL 5.7元数据库
    [ERROR] COLLATION 'latin1_swedish_ci' is not valid for CHARACTER SET 'utf8'
    .Net MVC断点进不去
  • 原文地址:https://www.cnblogs.com/ljy08163268/p/7634457.html
Copyright © 2011-2022 走看看