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;
}
 

原文地址:https://www.cnblogs.com/ljy08163268/p/7634457.html