CF Educational Round 12,A

来源:互联网 发布:生产数据化管理 编辑:程序博客网 时间:2024/06/16 05:53

A. Buses Between Cities
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard 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 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两个城市,有公交车从两个城市出去,到另一个城市。给你A,B城市公交车的发车频率和每一趟需要的时间(发车时间从5::00开始,24:00之后不再发车)你将会在某一趟从A到B的车上,求你在途中相遇(在起点终点相遇不管)的从B开向A的车的数量
题解:
(我不是很懂为啥他要给我A城市的发车频率,在解题是我只用到了从A城市发出的车的路上用时)
这个题比较有意思,最终的解法是:
我相遇的车是
1.出发时间早于我且还未到达A城市
2.出发时间在我之后,且出发时间在我到达B城市之前
使用两个数组分别储存每趟B车出发时间和每趟的到达时间(时间是从5:00开始的分钟数)
值得注意的我最初没有考虑这两个数组的大小,随便给了个比较大的值,于是就runtime error,泪崩
注意使用了string s来储存出发时间,通过字符串的计算得到出发的分钟数。

#include<iostream>#include<cstring>using namespace std;int main(){    int a;    int ta;    int b;    int tb;    int ans=0;    string time;    cin>>a>>ta;    cin>>b>>tb;    cin>>time;    int bstart[(1139/b)+5];    int bend[(1139/b)+5];    for(int i=1;b*(i-1)<=(19*60-1);i++){        bstart[i]=b*(i-1);        bend[i]=b*(i-1)+tb;    }    int astarttime=time[4]-'0'+(time[3]-'0')*10+60*(10*(time[0]-'0')+time[1]-'0'-5);    int aendtime=astarttime+ta;    for(int i=1;b*(i-1)<=(19*60-1);i++){        if((astarttime>bstart[i]&&astarttime<bend[i])||(astarttime<=bstart[i]&&aendtime>bstart[i]))            ans++;    }    cout<<ans<<endl;}
0 0