codeforces 868B Race Against Time

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.

题目大意:

给定一个时间,在不经过时分秒针的情况下,从第t1点到t2点

Input

Five integers h, m, s, t1, t2 (1 ≤ h ≤ 12, 0 ≤ m, s ≤ 59, 1 ≤ t1, t2 ≤ 12, t1 ≠ t2).

Misha's position and the target time do not coincide with the position of any hand.

Output

Print "YES" (quotes for clarity), if Misha can prepare the contest on time, and "NO" otherwise.

You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES").

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
Note

The three examples are shown on the pictures below from left to right. The starting position of Misha is shown with green, the ending position is shown with pink. Note that the positions of the hands on the pictures are not exact, but are close to the exact and the answer is the same.

 模拟,但有细节

算出double类型的详细时间,把针所指的都统一成60格一周的单位,即把小时×5

再把查询统一

接下来破环成链,模拟判断就行了

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<algorithm>
 4 #include<cstring>
 5 using namespace std;
 6 double h,m,s,t1,t2,h2,m2,s2;
 7 int flag1,flag2;
 8 int main()
 9 {
10   cin>>h>>m>>s>>t1>>t2;
11   t1*=5.0;t2*=5.0;
12   m=m+s/60;
13   if (m>=60.0) m-=60.0;
14   h=h*5+m/12;
15   if (h>=60.0) h-=60.0;
16   s2=60.0+s;
17   m2=60.0+m;
18   h2=60.0+h;
19   if (t1>t2) swap(t1,t2);
20   flag1=1;
21   if ((t1<s&&s<t2)||(t1<s2&&s2<t2)||(t1<m&&m<t2)||(t1<m2&&m2<t2)||(t1<h&&h<t2)||(t1<h2&&h2<t2))
22     {
23       flag1=0;
24     }
25   t1+=60;
26   if (t1>t2) swap(t1,t2);
27   flag2=1;
28   if ((t1<s&&s<t2)||(t1<s2&&s2<t2)||(t1<m&&m<t2)||(t1<m2&&m2<t2)||(t1<h&&h<t2)||(t1<h2&&h2<t2))
29     {
30       flag2=0;
31     }
32   if (flag1||flag2) cout<<"YES\n";
33   else cout<<"NO\n";
34 }

 

posted @ 2017-10-05 19:48  Z-Y-Y-S  阅读(499)  评论(0编辑  收藏  举报