• Codeforces A. Serval and Bus


    inputstandard input
    outputstandard output
    It is raining heavily. But this is the first day for Serval, who just became 3 years old, to go to the kindergarten. Unfortunately, he lives far from kindergarten, and his father is too busy to drive him there. The only choice for this poor little boy is to wait for a bus on this rainy day. Under such circumstances, the poor boy will use the first bus he sees no matter where it goes. If several buses come at the same time, he will choose one randomly.
    Serval will go to the bus station at time t, and there are n bus routes which stop at this station. For the i-th bus route, the first bus arrives at time si minutes, and each bus of this route comes di minutes later than the previous one.
    As Serval’s best friend, you wonder which bus route will he get on. If several buses arrive at the same time, you can print any of them.
    Input
    The first line contains two space-separated integers n and t (1≤n≤100, 1≤t≤105) — the number of bus routes and the time Serval goes to the station.
    Each of the next n lines contains two space-separated integers si and di (1≤si,di≤105) — the time when the first bus of this route arrives and the interval between two buses of this route.
    Output
    Print one number — what bus route Serval will use. If there are several possible answers, you can print any of them.
    Examples
    inputCopy
    2 2
    6 4
    9 5
    outputCopy
    1
    inputCopy
    5 5
    3 3
    2 5
    5 6
    4 9
    6 1
    outputCopy
    3
    inputCopy
    3 7
    2 2
    2 3
    2 4
    outputCopy
    1
    Note
    In the first example, the first bus of the first route arrives at time 6, and the first bus of the second route arrives at time 9, so the first route is the answer.

    In the second example, a bus of the third route arrives at time 5, so it is the answer.

    In the third example, buses of the first route come at times 2, 4, 6, 8, and so fourth, buses of the second route come at times 2, 5, 8, and so fourth and buses of the third route come at times 2, 6, 10, and so on, so 1 and 2 are both acceptable answers while 3 is not.

    思路:第一行输入的是公交车路线(n)和到车站的时间(t),下面n行是第n条线路车到达的时间(si)和下一辆车到达时间的间隔(di),所以我们只要求第n行的到达是时间加上间隔时间大于车站的时间(t),这行的下标+1就是答案。
    AC代码如下:

     1 #include"iostream"
     2 #include"algorithm"
     3 #include"cstdio"
     4 #include"cstring"
     5 using namespace std;    
     6 int a[100005],b[100005],i,j,m,n,t,;
     7 int main(){
     8     while(cin>>n>>t){
     9         int min=100000000;
    10         memset(a,0,sizeof(a));
    11         memset(b,0,sizeof(b));
    12         for(i=0;i<n;i++){
    13             scanf("%d %d",&a[i],&b[i]);
    14                         }
    15          for(i=0;i<n;i++){
    16              while(a[i]<t){ 
    17                  a[i]+=b[i];
    18              }
    19              if(min>a[i]){
    20                  min=a[i];
    21                  m=i; 
    22              }
    23               }
    24                 cout<<m+1<<endl;
    25             }    
    26     return 0;
    27 }
  • 相关阅读:
    基于node.js 的 websocket的移动端H5直播开发
    c# 基于RTMP推流 PC+移动端 拉流播放
    Android Studio解决Error:moudle not specified
    能ping通域名,却不能上网
    转 Postman访问Webapi的Get/Post/Put/Delte请求
    Sqlite 参数化 模糊查询 解决方案
    autofac使用总结
    windows7 安装pytorch
    linux nginx 如何配置多个端口
    委托应用实例演变
  • 原文地址:https://www.cnblogs.com/huangdf/p/12227141.html
Copyright © 2020-2023  润新知