CodeForces

来源:互联网 发布:vm14安装ubuntu 教程 编辑:程序博客网 时间:2024/04/30 08:48

题目:

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城通公交车,从B城到A城也通公交车,有一个人是A城的公交车司机,他想在他去B城的路上数一数他能碰到几辆公交车(也就是碰见几辆从B城到A城的车)
这两种公交车通车的时间是从05:00~23:59,然后题目给出了三组数据,
第一行是从A城到B城的发车时间的间隔和需要多少时间可以到达B城
第二行是从B城到A城的发车时间的时间间隔和需要多少时间到A城
第三行代表这个人从A城出发的时间

这道题的做法就是把B城开始发车的所有时间间隔都枚举出来,然后和这个人的发车时间作比较,计算时间是否相交,相交的话就记录一辆

代码:

#include <cstdio>#include <cstring>#include <cctype>#include <string>#include <set>#include <iostream>#include <stack>#include <cmath>#include <queue>#include <vector>#include <algorithm>#define mem(a,b) memset(a,b,sizeof(a))#define inf 0x3f3f3f3f#define mod 10000007#define debug() puts("what the fuck!!!")#define N 111111#define M 1000000#define ll long longusing namespace std;struct node{    int l,r;} zz[1000];int main(){    int a,ta,b,tb,hh,mm;    scanf("%d%d%d%d",&a,&ta,&b,&tb);    scanf("%d:%d",&hh,&mm);    int num=0;    int st=5*60;    int ed=23*60+59;    while(st<=ed)    {        zz[num].l=st;        zz[num].r=zz[num].l+tb;        st+=b;        num++;    }    int a_st=hh*60+mm;    int a_ed=a_st+ta;    int ans=0;    for(int i=0; i<num; i++)    {        if(a_st<zz[i].r&&zz[i].l<a_ed)            ans++;    }    printf("%d\n",ans);    return 0;}
0 0