zoukankan      html  css  js  c++  java
  • 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;
    }
  • 相关阅读:
    梅特卡夫法则(Metcalfe's law)
    jffs2reset 实现分析
    uhttpd配置文件分析
    疑问????
    ubuntu 修改root密码
    原始套接字
    位操作
    linux命令readlink
    awk 中 FS的用法
    Python做简单爬虫(urllib.request怎么抓取https以及伪装浏览器访问的方法)
  • 原文地址:https://www.cnblogs.com/zhangchengc919/p/5415736.html
Copyright © 2011-2022 走看看