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. 分水岭算法(理论+opencv实现)

    分水岭算法理论 从意思上就知道通过用水来进行分类,学术上说什么基于拓扑结构的形态学...其实就是根据把图像比作一副地貌,然后通过最低点和最高点去分类! 原始的分水岭: 就是上面说的方式,接下来用一幅图 ...

  2. PHP图片压缩

    <?php /** * 分享请保持网址.尊重别人劳动成果.谢谢. * 图片压缩类:通过缩放来压缩.如果要保持源图比例,把参数$percent保持为1即可. * 即使原比例压缩,也可大幅度缩小.数 ...

  3. javascript日期相减,求时间差

    //计算时间差 var from_date = new Date(from_time); var end_date = new Date(end_time); var time_different = ...

  4. net 编译报错:编辑器或项目正在尝试签出在内存中修改的文件,这将导致保存该文件

    1,报错提示: 编辑器或项目正在尝试签出在内存中修改的文件,这将导致保存该文件. 在生成过程中保存文件是危险的,这可能会在将来导致不正确的生成输出. 是否仍然继续签出? 2,原因:licenses.l ...

  5. java ee7 -- Java Bean验证

    针对对象.对象成员.方法.构造函数的数据验证. 1. 一个验证的小例子 (1) 添加引用jar <dependency> <groupId>org.hibernate.vali ...

  6. Mysql 日期类型 date、datetime、timestamp.

    三种:  date.datetime.timestamp. date : 格式 "YYYY-MM-DD" ,范围 "1000-00-00"到"9999 ...

  7. python中join()函数、list()函数补充的用法

    ---恢复内容开始--- Python join() 方法用于将序列中的元素(必须是str) 以指定的字符 连接生成一个新的字符串. list=[','a','b','c'] print(''.joi ...

  8. 1 python 文件处理

    1.打开文件open 函数 open函数最常用的使用方法如下:文件句柄 = open('文件路径', '模式',编码方式). encode='' 1.关于文件路径 #文件路径: 主要有两种,一种是使用 ...

  9. Asp.Net MVC参考资料

    Every day up!!!!!! 1.无废话MVC入门教程 2.MVC快速入门 3.MVC小牛之路 4.Web API强势入门指南 5.全网最全的mvc汇总 6.MVC5+EF6+Bootstra ...

  10. json decimal and datetime

    python json模块默认不能序列化decimal和datetime数据,可以通过自定义一个序列化的类实现: link: http://www.cnblogs.com/buxizhizhoum/p ...