Buses Between Cities (CodeForces - 665A )

Buses Between Cities (CodeForces - 665A )

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 format hh: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.

Examples

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和城市B之间有公交车,第一班在早上5点,末班车不晚于晚上11点59分出发。从A市来的公共汽车每A分钟一班,到B市来的公共汽车每B分钟一班,到A市来的公共汽车每B分钟一班,到A市来的公共汽车每tb分钟一班。

司机Simion想让他的工作多样化,所以他数了数向他驶来的公交车。Simion没有计算他在开始和结束时遇到的公共汽车。

你知道西米恩从A市出发到b市的时间。计算一下西米恩将会遇到多少辆公共汽车。

输入

第一行包含两个整数a, ta(1≤a, ta≤120)——从a市到B市的公交车频率和行驶时间。两个值都以分钟为单位给出。

第二行包含两个整数b tb(1≤b, tb≤120)——从b市到A市的公交车班次和行驶时间。两个值都以分钟为单位给出。

最后一行是Simion离开A城市的时间,格式为hh:mm。保证那时有一辆从a市来的公共汽车。注意,小时和分钟是用两个数字表示的。

输出

打印唯一整数z——Simion将在路上遇到的总线数。注意,你不应该计算在A和B城市的遭遇。

请注意

在第一个例子中,Simion在早上5:20离开城市A,在早上5:50到达城市B。他将在这段时间(05:00 AM - 05:40 AM)迎接从B市出发的首批5辆公交车。西缅也将在早上5点50分在B城与一辆公共汽车会合,但他没有数。

还请注意,第一次相遇将在上午5点26分至5点27分之间(如果我们建议公交车以持续的速度行驶)。

思路:有两个城市A和B,从A城到B城通公交车,从B城到A城也通公交车,有一个人是A城的公交车司机,他想在他去B城的路上数一数他能碰到几辆公交车(也就是碰见几辆从B城到A城的车) 
这两种公交车通车的时间是从05:00~23:59,然后题目给出了三组数据, 
第一行是从A城到B城的发车时间的间隔和需要多少时间可以到达B城 
第二行是从B城到A城的发车时间的时间间隔和需要多少时间到A城 
第三行代表这个人从A城出发的时间

AC代码:

#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <string.h>
#include <queue>
#include <stack>
#include <map>
using namespace std;
int main()
{
    int a,ta,b,tb,h,m;
    int sum=0;
    scanf("%d%d%d%d %d:%d",&a,&ta,&b,&tb,&h,&m);
    m+=60*h;
    for(int i=300;i<1440;i+=b)
    {
        if(i+tb>m && i<m+ta)
            sum++;
    }
    printf("%d\n",sum);
    return 0;
}


 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值