Buses Between Cities
来源:互联网 发布:重生之大英雄 知乎 编辑:程序博客网 时间:2024/06/09 19:56
Buses Between Cities
Buses run between the cities A and B, the first one is at 05:00 AM and the last one departs not later than at 11:59 PM. A bus from the city A departs every a minutes and arrives to the city B in a ta minutes, and a bus from the city B departs every bminutes and arrives to the city A in a tb minutes.
The driver Simion wants to make his job diverse, so he counts the buses going towards him. Simion doesn't count the buses he meet at the start and finish.
You know the time when Simion departed from the city A to the city B. Calculate the number of buses Simion will meet to be sure in his counting.
The first line contains two integers a, ta (1 ≤ a, ta ≤ 120) — the frequency of the buses from the city A to the city B and the travel time. Both values are given in minutes.
The second line contains two integers b, tb (1 ≤ b, tb ≤ 120) — the frequency of the buses from the city B to the city A and the travel time. Both values are given in minutes.
The last line contains the departure time of Simion from the city A in the formathh:mm. It is guaranteed that there are a bus from the city A at that time. Note that the hours and the minutes are given with exactly two digits.
Print the only integer z — the number of buses Simion will meet on the way. Note that you should not count the encounters in cities A and B.
10 3010 3505:20
5
60 12024 10013:00
9
In the first example Simion departs form the city A at 05:20 AM and arrives to the city B at 05:50 AM. He will meet the first 5 buses from the city B that departed in the period [05:00 AM - 05:40 AM]. Also Simion will meet a bus in the city B at 05:50 AM, but he will not count it.
Also note that the first encounter will be between 05:26 AM and 05:27 AM (if we suggest that the buses are go with the sustained speed).
/*题意:在A地每a分钟就有一辆车出发,经过ta分钟到达B地,在B地则每b分钟有一辆车出发,经过tb分钟到达A地。发车时间限制为早上5:00到晚上11:59。Simion在hh:mm从A地上了一辆车,问他在车上可以遇见多少辆从B地开往A地的车,当他处于A地或者B地时遇见的不计。*/#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;int main(){int a,ta,b,tb,h,m;while(scanf("%d%d%d%d %d:%d",&a,&ta,&b,&tb,&h,&m)!=EOF){int time=h*60+m;//时分转化 int ans=0;int tt=time+ta;//到达B的时间 for(int i=0;;i++){int start=300+i*b;int end=start+tb;if(start>=tt)//到达B地退出 break;if(start>=1440)//发车时间超过晚上十二点,退出 break;if(end<=time)//B发的车到达A,还没上车 continue;if(end>time||start<tt)//满足条件 ans++;}printf("%d\n",ans);}}
- cf655A Buses Between Cities
- Buses Between Cities
- CodeForces 665A Buses Between Cities
- CodeForces 665A Buses Between Cities
- Codeforces 665A - Buses Between Cities
- Educational Codeforces Round 12 A. Buses Between Cities
- Educational Codeforces Round 12 A. Buses Between Cities
- hdu2874 Connections between cities
- HDU Connections between cities
- HDU2874 Connections between cities
- Connections between cities
- Connections between cities
- hdu2874 Connections between cities
- Connections between cities
- Connections between cities HDU
- Connections between cities HDU
- HDOJ 2874 Connections between cities
- HDU 2874 Connections between cities
- eclipse插件开发
- 深入理解SQL的四种连接-左外连接、右外连接、内连接、全连接
- JavaScript数组中的22个常用方法
- linux 安装svn服务端
- mysql:sql order by */* desc (查询)
- Buses Between Cities
- Java取一个数组里面第二大的数
- dom4j写文件的编码(UTF-8)问题(主要指中文)的解决
- opencv源码之均值滤波(2)
- 特性训练
- HTTP & RTMP 直播比较
- yuangen
- Hi3515 CRQCV100 NVR折腾记
- Lua 运算符