I am a slow walker,but I never walk backwards. Abraham Lincoln

GeekZRF

Codeforces 665A. Buses Between Cities 模拟

A. Buses Between Cities
time limit per test:
1 second
memory 
limit per test:
256 megabytes
input:
standard input
output:
standard output

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 b minutes 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 Aand 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).

题目链接:http://codeforces.com/problemset/problem/665/A


题意:公交车在A,B两个城市之间运行。从A到B的公交车每隔a分钟发车一次,到达B需要ta分钟;从B到A的公交车每隔b分钟发车一次,到达A需要tb分钟。最早发车时间为上午5:00,最晚发车时间不能超过下午11:59。hh:mm出发一辆车从A出发到达B的途中会遇到多少辆公交车(不包括A,B两地)。

思路:就是求时间区间(hh:mm-tb,hh:mm+ta)内有多少辆从B到A的公交车发车。

代码:

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAXN = 1e5 + 100, mod = 1e9 + 7, inf = 0x3f3f3f3f;
typedef long long ll;
const ll INF = (1ll<<60);
int main()
{
    int a,ta,b,tb,hh,mm;
    int t,s=60*5,e=23*60+59;
    int l=0,r=0;
    scanf("%d%d%d%d",&a,&ta,&b,&tb);
    scanf("%d:%d",&hh,&mm);
    t=hh*60+mm;
    l=t-tb;
    r=t+ta;
    //cout<<l<<" "<<r<<endl;
    int ans=0;
    while(s<=e)
    {
        if(s>l&&s<r) ans++;
        s+=b;
        if(s>r) break;
    }
    cout<<ans<<endl;
    return 0;
}
View Code

 

posted on 2016-05-21 13:47  GeekZRF  阅读(439)  评论(0编辑  收藏  举报

导航