zoukankan      html  css  js  c++  java
  • 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
    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 + 100, mod = 1e9 + 7, inf = 0x3f3f3f3f;
    typedef long long ll;
    const ll INF = (1ll<<60);
    int main()
    {
        int a,ta,b,tb,hh,mm;
        int t,s=60*5,e=23*60+59;
        int l=0,r=0;
        scanf("%d%d%d%d",&a,&ta,&b,&tb);
        scanf("%d:%d",&hh,&mm);
        t=hh*60+mm;
        l=t-tb;
        r=t+ta;
        //cout<<l<<" "<<r<<endl;
        int ans=0;
        while(s<=e)
        {
            if(s>l&&s<r) ans++;
            s+=b;
            if(s>r) break;
        }
        cout<<ans<<endl;
        return 0;
    }
    View Code
    I am a slow walker,but I never walk backwards.
  • 相关阅读:
    如何组建开发团队-建立畅通的沟通渠道
    如何组建开发团队-激励团队气势
    文件夹名与类名一致造成的命名空间无法识别的问题
    SQL Server 还原错误“restore database正在异常终止 错误 3154”
    S​Q​L​ ​S​e​r​v​e​r​ ​服务无法启动,错误1069解决办法
    无法升级数据库....因为此版本的 SQL Server 不支持该数据库的非发布版本(539) 解决方案
    图解Microsoft SQL Server——“远程过程调用失败 [0x800706be] 错误“。
    Eclipse: Android Device Chooser
    部署网站时的错误“one of its dependencies.试图加载格式不正确的程序。”解决方案。
    把char赋值到string里面
  • 原文地址:https://www.cnblogs.com/GeekZRF/p/5514612.html
Copyright © 2011-2022 走看看