Codeforces Round #438 B. Race Against Time
来源:互联网 发布:淘宝卖家关闭佣金 编辑:程序博客网 时间:2024/06/08 05:54
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.
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.
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").
12 30 45 3 11
NO
12 0 1 12 1
YES
3 47 0 4 9
YES
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.
判断两个点是否在一个时间段内,注意有12点到1点的跨度处理
#include <iostream>#include <algorithm>using namespace std;int main() { int h,m,s,t1,t2; double hq,mq,sq,t1q,t2q,a,b,c; cin>>h>>m>>s>>t1>>t2; a=hq=h*30+m*0.5+s*0.5/60; if(a>=360) a-=360; b=mq=m*6+s*1.0/10; c=sq=s*6; t1q=t1*30; t2q=t2*30; if(a>b) swap(a, b); if(a>c) swap(a, c); if(b>c) swap(b, c); if(t1q>=a&&t1q<=b&&t2q>=a&&t2q<=b) cout<<"YES"<<endl; else if(t1q>=b&&t1q<=c&&t2q>=b&&t2q<=c) cout<<"YES"<<endl; else if((t1q>=c&&t1q<=a+360&&t2q>=c&&t2q<=a+360)||(t1q+360>=c&&t1q+360<=a+360&&t2q>=c&&t2q<=a+360)|| (t1q>=c&&t1q<=a+360&&t2q+360>=c&&t2q+360<=a+360)|| (t1q+360>=c&&t1q+360<=a+360&&t2q+360>=c&&t2q+360<=a+360))//处理跨度 cout<<"YES"<<endl; else cout<<"NO"<<endl; // insert code here... //std::cout << "Hello, World!\n"; return 0;}
- Codeforces Round #438 B. Race Against Time
- Codeforces Round #438 (868B) B Race Against Time
- Codeforces Round #438 B. Race Against Time 思路很重要
- Codeforces Round #438 B Race Against Time(模拟)
- Codeforces Round #438 B. Race Against Time 题解
- Codeforces Round #438 (Div. 1 + Div. 2 combined) B. Race Against Time(模拟)
- Codeforces Round #438 (Div. 1 + Div. 2 combined) B. Race Against Time
- CodeFroces Round 438 B.Race Against Time(模拟)
- codeforces 868B Race Against Time
- Codeforces 868B. Race Against Time 模拟
- 【Codeforces 868 B. Race Against Time】& 模拟
- CodeForces 868B Race Against Time
- codeforces 868B Race Against Time
- Codeforces 868 B Race Against Time(水题)
- CF 868 B. Race Against Time【模拟】
- Codeforces868B Race Against Time
- Codeforce Race Against Time
- SPOJ 3261. Race Against Time(RACETIME)(分块)
- java基础-多态-接口
- Java并发编程:深入剖析ThreadLocal
- JZOJ5397. 【NOIP2017提高A组模拟10.6】Biology trie+LCA/哈希
- 2017-10-6离线赛总结
- codeforces 862b
- Codeforces Round #438 B. Race Against Time
- 焦点事件
- const的用法,特别是用在函数前面与后面的区别!
- 谈谈对Spring IOC的理解
- 还记得被东方project弹幕支配的恐惧吗
- Windows系列及开源
- python中实例属性和类属性之间的关系
- 自定义控件轮播图联系
- Hibernate一对多双向,多对多双向,排序