【Codeforces 868 B. Race Against Time】& 模拟
来源:互联网 发布:淘宝查号网址 编辑:程序博客网 时间:2024/05/20 15:56
B. Race Against Time
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard 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
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.
题意 : 能否从 t1 到达 t2,顺时针或逆时针,中间的时针,分针,秒针会挡着路
思路 : 顺 || 逆时针各模拟一下
AC代码:
#include<cstdio>#include<cmath>#include<deque>#include<queue>#include<vector>#include<cstring>#include<algorithm>using namespace std;const int MAX = 1e5 + 10;const int INF = 1e9 + 7;typedef long long LL;bool sf(double x,double y,double z){ if(z <= x || z >= y) return true; return false;}int main(){ double h,m,s,h1,h2; scanf("%lf %lf %lf %lf %lf",&h,&m,&s,&h1,&h2); m += s / 60,h += m / 60; double ma = m / 5,ms = s / 5; if(h1 > h2) swap(h1,h2); if(sf(h1,h2,h) && sf(h1,h2,ma) && sf(h1,h2,ms)){ puts("YES"); return 0; } if(h1 < h2) h1 += 12; double x = h + 12,y = ma + 12,z = ms + 12; if(sf(h2,h1,x) && sf(h2,h1,y) && sf(h2,h1,z) && sf(h2,h1,h) && sf(h2,h1,ma) && sf(h2,h1,ms)){ puts("YES"); return 0; } puts("NO"); return 0;}
- Codeforces 868B. Race Against Time 模拟
- 【Codeforces 868 B. Race Against Time】& 模拟
- CF 868 B. Race Against Time【模拟】
- codeforces 868B Race Against Time
- CodeForces 868B Race Against Time
- codeforces 868B Race Against Time
- Codeforces Round #438 B Race Against Time(模拟)
- Codeforces Round #438 (868B) B Race Against Time
- Codeforces 868 B Race Against Time(水题)
- Codeforces Round #438 B. Race Against Time
- Codeforces Round #438 (Div. 1 + Div. 2 combined) B. Race Against Time(模拟)
- CodeFroces Round 438 B.Race Against Time(模拟)
- Codeforces Round #438 B. Race Against Time 思路很重要
- Codeforces Round #438 B. Race Against Time 题解
- Codeforces868B Race Against Time (模拟)
- Codeforces Round #438 (Div. 1 + Div. 2 combined) B. Race Against Time
- Codeforces868B Race Against Time
- Codeforce Race Against Time
- 结构型设计模式之代理模式
- 强烈推荐的机器学习,深度学习课程以及python库
- simple traditional layout in html(use table)
- 2款风格QPushButton
- FTPrep, 100 Same Tree
- 【Codeforces 868 B. Race Against Time】& 模拟
- mybatis-generator 代码自动生成工具(maven方式)
- web前端动态添加进度条
- 必须了解的一些IT知识点
- SSL默认有5年的限制
- 源表测量准确度Accurracy(以Keithley 4200为例)
- Construct2游戏制作入门教程
- 未能加载文件或程序集“**”或它的某一个依赖项,系统找不到指定的文件
- 总结自己Python环境配置过程和碰到的问题