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 + , mod = 1e9 + , inf = 0x3f3f3f3f;
typedef long long ll;
const ll INF = (1ll<<);
int main()
{
int a,ta,b,tb,hh,mm;
int t,s=*,e=*+;
int l=,r=;
scanf("%d%d%d%d",&a,&ta,&b,&tb);
scanf("%d:%d",&hh,&mm);
t=hh*+mm;
l=t-tb;
r=t+ta;
//cout<<l<<" "<<r<<endl;
int ans=;
while(s<=e)
{
if(s>l&&s<r) ans++;
s+=b;
if(s>r) break;
}
cout<<ans<<endl;
return ;
}

Codeforces 665A. Buses Between Cities 模拟的更多相关文章

  1. codeforces 665A Buses Between Cities

    简单题 #include<cstdio> #include<cstring> #include<cmath> #include<vector> #inc ...

  2. codeforces 665A A. Buses Between Cities(水题)

    题目链接: A. Buses Between Cities time limit per test 1 second memory limit per test 256 megabytes input ...

  3. Educational Codeforces Round 12 A. Buses Between Cities 水题

    A. Buses Between Cities 题目连接: http://www.codeforces.com/contest/665/problem/A Description Buses run ...

  4. CodeForces.158A Next Round (水模拟)

    CodeForces.158A Next Round (水模拟) 题意分析 校赛水题的英文版,坑点就是要求为正数. 代码总览 #include <iostream> #include &l ...

  5. Codeforces C. Jzzhu and Cities(dijkstra最短路)

    题目描述: Jzzhu and Cities time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  6. Educational Codeforces Round 12 A. Buses Between Cities

    题意: 从A到B的汽车每隔 a 分钟发车一次,从A到B要ta分钟. 从B到A汽车每隔b分钟发车一次,从B到A要ta分钟. Simion从A出发,问他在A->B的途中共遇到了多少辆车. 汽车都是从 ...

  7. Codeforces 703B. Mishka and trip 模拟

    B. Mishka and trip time limit per test:1 second memory limit per test:256 megabytes input:standard i ...

  8. Codeforces 747C:Servers(模拟)

    http://codeforces.com/problemset/problem/747/C 题意:有n台机器,q个操作.每次操作从ti时间开始,需要ki台机器,花费di的时间.每次选择机器从小到大开 ...

  9. Codeforces 740A. Alyona and copybooks 模拟

    A. Alyona and copybooks time limit per test: 1 second memory limit per test: 256 megabytes input: st ...

随机推荐

  1. 外观设计模式 (Facade)

    目的:为子系统中的一组接口提供一个一致的界面,此模式定义了一个高层接口,这个接口使得这一子系统更加容易使 外观设计模式使用场合: 1. 在设计初期阶段,应该有意识的将不同的两个分层.层与层之间建立外观 ...

  2. JS - 循环,条件if,switch,while

    1.循环格式: 定义初始值    终止条件 // 1.将i的值写在里面 for(var i=0;i;i ++){ console.log(i); }// 2.也可以将i的值写在外面,分号必须还在 va ...

  3. OpenACC 计算构建内的自定义函数

    ▶ 使用 routine 构件创建的自定义函数,在并行调用上的差别 ● 代码,自定义一个 sqab 函数,使用内建函数 fabsf 和 sqrtf 计算一个矩阵所有元素绝对值的平方根 #include ...

  4. js前台遍历后台返回的Datatable数据

    jsondata 后台返回的datatable ) { ; j < jsondata.length; j++) { jsondata[j]; }; }

  5. mysql大表优化

    https://segmentfault.com/a/1190000006158186 https://tech.meituan.com/mysql-index.html http://www.cnb ...

  6. delphi webbrowser 执行 js ---转

    EmbeddedWB1.OleObject.document.parentWindow.execScript(memo1.Text, 'javascript');

  7. 在Eclipes中查看源代码和大纲快速定位

    1 在Eclipes中查看源代码,快捷键使用clrl+光标,选择你要查看的方法和属性查看源代码.例如你想看StringBuilder这个类源代码 StringBuilder allow = new S ...

  8. 吴裕雄 python 数据处理(1)

    import time print(time.time())print(time.localtime())print(time.strftime('%Y-%m-%d %X',time.localtim ...

  9. 吴裕雄 实战PYTHON编程(5)

    text = '中华'print(type(text))#<class 'str'>text1 = text.encode('gbk')print(type(text1))#<cla ...

  10. Appuim学习路-Appuim介绍

    (学一个东西,总的知道它支持什么.为什么要选择它吧?所以我就去看github上的介绍了.发现大家介绍的来源大多来自于此)   Appium是一个开源的自动化框架,是跨平台的,允许所有平台使用同一套AP ...