专栏首页算法修养CodeForces 665A Buses Between Cities

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

#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <algorithm>
#include <math.h>

using namespace std;
struct Node{
   int l,r; 
}a1[10005];
int a,ta;
int b,tb;
int hh,mm;
int time(int hh,int mm){
	return hh*60+mm;
}
int main(){
	scanf("%d%d",&a,&ta);
	scanf("%d%d",&b,&tb);
	scanf("%d:%d",&hh,&mm);
	int start=time(5,0);
	int end=time(23,59);
	int cnt=0;
	while(start<=end)
	{
       a1[cnt].l=start;
	   a1[cnt].r=a1[cnt++].l+tb;
	   start+=b;
	}
	Node b1;b1.l=time(hh,mm);b1.r=b1.l+ta;
	int ans=0;
	for(int i=0;i<cnt;i++)
	{
		if(b1.r>a1[i].l&&b1.l<a1[i].r)
			ans++;
	}
	printf("%d\n",ans);
	return 0;

}

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

我来说两句

0 条评论
登录 后参与评论

相关文章

  • HOJ-2056 Bookshelf(线性动态规划)

    L is a rather sluttish guy. He almost never clean up his surroundings or regulat...

    ShenduCC
  • ZOJ 3202 Second-price Auction

    Time Limit: 1 Second      Memory Limit: 32768 KB

    ShenduCC
  • CodeForces 665B Shopping

    B. Shopping time limit per test 1 second memory limit per test 256 megabyt...

    ShenduCC
  • poj1611---The Suspects

    The Suspects Time Limit: 1000MS Memory Limit: 20000K Total Submissions: ...

    Gxjun
  • ZOJ 3202 Second-price Auction

    Time Limit: 1 Second      Memory Limit: 32768 KB

    ShenduCC
  • Codeforces 626D Jerry's Protest(暴力枚举+概率)

    D. Jerry's Protest time limit per test:2 seconds memory limit per test:256 megab...

    Angel_Kitty
  • Codeforces Beta Round #72 (Div. 1 Only)B. Doctor

    There are n animals in the queue to Dr. Dolittle. When an animal comes into the ...

    glm233
  • 另类Alpha:基于供应链数据的量化因子挖掘

    在量化交易中,如何获取适当的数据用于开发和测试交易策略,往往是投资者面临的难题。随着技术的发展,获取大数据的成本不断降低,但历史价格等传统数据已完全无法满足投资...

    量化投资与机器学习微信公众号
  • 2019.8.15乘兴打Codeforces Round #569 (Div. 2)小记

    Recently, on the course of algorithms and data structures, Valeriy learned how t...

    glm233
  • The Note based on Data Structures and Algorithm Analysis in C CHAPTER 3 P1

    The Note based on Data Structures and Algorithm Analysis in C

    Chiptune

扫码关注云+社区

领取腾讯云代金券