Buses Between Cities

xiaoxiao2021-02-27  312

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.

Input

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.

Output

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.

Example Input 10 30 10 35 05:20 Output 5 Input 60 120 24 100 13:00 Output 9 Note

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); } }

转载请注明原文地址: https://www.6miu.com/read-3771.html

最新回复(0)