Educational Codeforces Round 12 A. Buses Between Cities

16 篇文章 0 订阅
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 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
 
   
题意:汽车在A、B两个城市往返。从A到B的汽车每隔a分钟发车一次,从A到B要ta分钟。从B到A汽车每隔b分钟发车一次,从B到A要ta分钟。 Simion 从A出发,问他在A->B的途中共遇到了多少辆车。汽车都是从上午5.00出发,最晚到晚上11.59.
解法;首先,由于输入的小时和分钟数,我们可以将时间转换成分钟。然后我们只需要求在simion从出发到到达B的时间内从B站发出的车总数和smion出发时,B->A的还在路上的车。然后求和就行了。我们还可以模拟发车的着个过程,统计满足要求的车的个数。
AC:
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<ctype.h>
using namespace std;
const int maxn=24*60;
int main()
{
   int a,b,ta,tb,h,m,cnt;
   char c;
   scanf("%d%d",&a,&ta);
   scanf("%d%d",&b,&tb);
   scanf("%d%c%d",&h,&c,&m);
   int st=h*60+m;
   int ed=h*60+m+ta;
   int s=5*60;
   cnt=0;
   while(s<60*24)
   {
       if(((s+tb)>st&&s<ed)||(s<ed&&s>st) )cnt++;
       s+=b;
   }
   printf("%d\n",cnt);
}





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值