Codeforces Round #438 (Div. 1 + Div. 2 combined) B. Race Against Time
来源:互联网 发布:java字符串处理题目 编辑:程序博客网 时间:2024/06/08 03:11
B. Race Against Time
Problem statement
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
Example 1
Input
12 30 45 3 11
Output
NO
Example 2
Input
12 0 1 12 1
Output
YES
Example 3
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.
题意
给您时针、分针和秒针的位置以及一个人在时钟上的起始点和终点,问你是否能不跨过任何一根针来从起点沿着圆盘走到终点
思路
只要将时针,分针和秒针的位置都化为时、分、秒的样式,然后从起点到终点从两个方向一秒一秒遍历下去就行了。(做法有些奇特,至于如何转化详情请见代码)
Code
#include<bits/stdc++.h>using namespace std;typedef long long ll;inline void readInt(int &x) { x=0;int f=1;char ch=getchar(); while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();} while(isdigit(ch))x=x*10+ch-'0',ch=getchar(); x*=f;}inline void readLong(ll &x) { x=0;int f=1;char ch=getchar(); while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();} while(isdigit(ch))x=x*10+ch-'0',ch=getchar(); x*=f;}/*================Header Template==============*/int h[5],m[5],s[5];bool f1=1,f2=1;int main() { readInt(h[2]); readInt(h[3]); readInt(h[4]); readInt(h[0]); readInt(h[1]); m[0]=s[0]=m[1]=s[1]=0; m[2]=h[3]; s[2]=h[4]; m[3]=(h[3]%5)*12; int tmph3=0,tmph4=0; if(m[3]>=60) { tmph3+=m[3]/60; m[3]%=60; }//当时是这个if没加*1 s[3]=0; m[4]=(h[4]%5)*12; if(m[4]>=60) { tmph4+=m[4]/60; m[4]%=60; }//当时是这个if没加*2 s[4]=0; h[3]/=5; h[3]+=tmph3; if(h[3]==0) h[3]=12;//当时是这个if没加*3 h[4]/=5; h[4]+=tmph4; if(h[4]==0) h[4]=12;//当时是这个if没加*4// for(int i=0;i<=4;i++)// cout<<h[i]<<" "<<m[i]<<" "<<s[i]<<endl; int x=h[0],y=m[0],z=s[0]; while(x!=h[1]||y!=m[1]||z!=s[1]) {// cout<<x<<" "<<y<<" "<<z<<" "<<int(f1)<<endl; for(int i=2;i<=4;i++) { if(x==h[i]&&y==m[i]&&z==s[i]) { f1=0; break; } } z++; if(z==60) { y++; z=0; } if(y==60) { x++; y=0; } if(x==13) x=1; } x=h[1],y=m[1],z=s[1]; while(x!=h[0]||y!=m[0]||z!=s[0]) { for(int i=2;i<=4;i++) { if(x==h[i]&&y==m[i]&&z==s[i]) { f2=0; break; } } z++; if(z==60) { y++; z=0; } if(y==60) { x++; y=0; } if(x==13) x=1; } if(f1||f2) puts("YES"); else puts("NO"); return 0;}
- Codeforces Round #438 (Div. 1 + Div. 2 combined) B. Race Against Time(模拟)
- Codeforces Round #438 (Div. 1 + Div. 2 combined) B. Race Against Time
- 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) ABCDF
- Codeforces Round #438 (Div. 1 + Div. 2 combined)
- Codeforces Round #438 (Div. 1 + Div. 2 combined) 总结
- Codeforces Round #399 (Div. 1 + Div. 2, combined) B. Code For 1 线段树
- Codecraft-17 and Codeforces Round #391 (Div. 1 + Div. 2, combined)A+B
- Codeforces Round #397(Div. 1 + Div. 2 combined)B. Code obfuscation【水题】
- Codeforces Round #400 (Div. 1 + Div. 2, combined)B.Sherlock and his girlfriend【预处理素数+思维】
- ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined)A+B
- Codeforces Round #400 (Div. 1 + Div. 2, combined) 776B Sherlock and his girlfriend
- Codeforces Round #400 (Div. 1 + Div. 2, combined)D
- Codeforces Round #400 (Div. 1 + Div. 2, combined) C
- Ubuntu上搭建Hadoop时出现的一个问题
- linux 网络虚拟化:network namespace 简介
- Hibernate初学者---多对多双向关联数据表的CRUD增删改查
- BZOJ 1637: Balanced Lineup 巧妙变换
- shell的使用
- Codeforces Round #438 (Div. 1 + Div. 2 combined) B. Race Against Time
- STL学习笔记之union obj
- Java 9 linux安装与配置环境变量
- 什么是虚函数,虚函数和普通函数有何不同,带有虚函数的类什么时候都可以实例化吗?
- 在浏览器中输入www.baidu.com后执行的全部过程
- Linux 文件与目录管理 —— 创建、删除、移动与链接 mkdir mv rm ln
- ros 多个电脑通信
- 1134. Vertex Cover (25)
- 坚持#第203天~云计算平台