1. 程式人生 > >Codeforces Round #438 B. Race Against Time

Codeforces Round #438 B. Race Against Time

i++ bsp nbsp rac name esp pac 特殊 end

題意: 這題題意看了我好久,意思就是給你時針,分針,秒針,再給你一個起點和終點,起點和終點均為小於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;
}
 

Codeforces Round #438 B. Race Against Time