题目链接:
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.
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.
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.
10 30
10 35
05:20
5
60 120
24 100
13: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).
题意:
给出每隔多少分钟发车和经过多长时间到达目的地,为给的其中一辆车的发车时间,问这个车的司机能在路上遇到到多少辆车;
思路:
遇到的车都是到达时间在这辆车的发车时间之后和发车时间在这辆车到达时间之前的
AC代码:
/*2014300227 665A - 17 GNU C++11 Accepted 15 ms 2172 KB*/ #include <bits/stdc++.h> using namespace std; typedef long long ll; const int N=1e5+5; const ll mod=1e9+7; int a,ta,b,tb; char str[10],s; int main() { scanf("%d%c%d",&a,&s,&ta); scanf("%d%c%d",&b,&s,&tb); scanf("%s",str); int start=((str[0]-'0')*10+(str[1]-'0'))*60+(str[3]-'0')*10+(str[4]-'0'); int ending=start+ta; int l=300,r=24*60-1; int ans=0; for(int i=l;i<=r;i+=b) { if(i+tb>start&&i<ending)ans++; } cout<<ans<<"\n"; return 0; }