Codeforces Round #438 (Div. 1 + Div. 2 combined) B. Race Against Time(模拟)

水深无声 2022-06-07 01:59 195阅读 0赞

B. Race Against Time

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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.

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

  1. 12 30 45 3 11

output

  1. NO

input

  1. 12 0 1 12 1

output

  1. YES

input

  1. 3 47 0 4 9

output

  1. 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.

ec295def7dee59ce2831fcbb98f42706bfc82d78.png

题解:

还比较有意思的一题,就是给出时分秒,给出人要走的两个时间点(任何一个都可以作为起点和终点,可以顺时针也可以逆时针),问是否可以顺利走完(不碰到时分秒的针)

思路:

我开了120的数组,每2位表示一个刻度(为了处理不是整点的问题),如果分秒都为0,则时针的位置为h*10,否则随便加一个1-9的数字表示不是整点,同理如果秒为0,分针的位置为m*2,否则就为m*2+1,秒针就直接s*2,然后顺时针搞一遍,可以就输出yes,不行就逆时针搞一遍,可以就输出yes,否则就是no

暂时ac代码:

  1. #include<iostream>
  2. #include<cstring>
  3. #include<stdio.h>
  4. #include<math.h>
  5. #include<string>
  6. #include<stdio.h>
  7. #include<queue>
  8. #include<stack>
  9. #include<map>
  10. #include<vector>
  11. #include<deque>
  12. #include<algorithm>
  13. #define ll long long
  14. #define INF 1008611111
  15. #define M (t[k].l+t[k].r)/2
  16. #define lson k*2
  17. #define rson k*2+1
  18. using namespace std;
  19. int vis[125];
  20. int main()
  21. {
  22. int t1,t2,h,m,s,tag=1,st,ed,i;
  23. scanf("%d%d%d%d%d",&h,&m,&s,&t1,&t2);
  24. memset(vis,0,sizeof(vis));
  25. if(h==12)
  26. h=0;
  27. if(m==0&&s==0)
  28. vis[h*10]=1;
  29. else
  30. vis[h*10+5]=1;
  31. if(s==0)
  32. vis[m*2]=1;
  33. else
  34. vis[m*2+1]=1;
  35. vis[s*2]=1;
  36. if(t1>t2)
  37. swap(t1,t2);
  38. st=t1*10;
  39. ed=t2*10;
  40. for(i=st;i<=ed;i++)
  41. {
  42. if(vis[i])
  43. {
  44. tag=0;
  45. break;
  46. }
  47. }
  48. if(tag)
  49. {
  50. printf("YES\n");
  51. return 0;
  52. }
  53. int flag=1;
  54. for(i=ed;i<=120;i++)
  55. {
  56. if(vis[i])
  57. {
  58. flag=0;
  59. break;
  60. }
  61. }
  62. for(i=0;i<=st;i++)
  63. {
  64. if(vis[i])
  65. {
  66. flag=0;
  67. break;
  68. }
  69. }
  70. if(flag)
  71. printf("YES\n");
  72. else
  73. printf("NO\n");
  74. return 0;
  75. }

发表评论

表情:
评论列表 (有 0 条评论,195人围观)

还没有评论,来说两句吧...

相关阅读