• codeforces 665A A. 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).

    题意:

    给出每隔多少分钟发车和经过多长时间到达目的地,为给的其中一辆车的发车时间,问这个车的司机能在路上遇到到多少辆车;

    思路:

    遇到的车都是到达时间在这辆车的发车时间之后和发车时间在这辆车到达时间之前的

    AC代码:

    /*2014300227    665A - 17    GNU C++11    Accepted    15 ms    2172 KB*/
    #include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    const int N=1e5+5;
    const ll mod=1e9+7;
    int a,ta,b,tb;
    char str[10],s;
    int main()
    {
        scanf("%d%c%d",&a,&s,&ta);
        scanf("%d%c%d",&b,&s,&tb);
        scanf("%s",str);
        int start=((str[0]-'0')*10+(str[1]-'0'))*60+(str[3]-'0')*10+(str[4]-'0');
        int ending=start+ta;
        int l=300,r=24*60-1;
        int ans=0;
        for(int i=l;i<=r;i+=b)
        {
            if(i+tb>start&&i<ending)ans++;
        }
        cout<<ans<<"
    ";
        return 0;
    }
  • 相关阅读:
    C# 十大经典排序算法
    AMD处理器的Windows安装docker
    软件设计师全章节ppt
    方法重载(Overload)和方法重写(Override)快速区分!!
    数据库 case 用法
    @CacheEvict缓存
    Mysql 恢复ibd文件
    C# 获取IIS站点以及程序池信息
    洞察的力量
    阿里云服务器安装docker并部署redis
  • 原文地址:https://www.cnblogs.com/zhangchengc919/p/5415736.html
Copyright © 2020-2023  润新知