zoukankan      html  css  js  c++  java
  • 【CF 551A】Serval and Bus

    A. Serval and Bus
    time limit per test1 second
    memory limit per test256 megabytes
    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 ?, and there are ? bus routes which stop at this station. For the ?-th bus route, the first bus arrives at time ?? minutes, and each bus of this route comes ?? 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 ? and ? (1≤?≤100, 1≤?≤105) — the number of bus routes and the time Serval goes to the station.

    Each of the next ? lines contains two space-separated integers ?? and ?? (1≤??,??≤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.

    #include<iostream>
    using namespace std;
    int a[110], b[110];
    int main(){
        int n, t;
        cin>>n>>t;
        for(int i = 1; i <= n; i++)cin>>a[i]>>b[i];
        int mmin = 1000010, id = -1;
        for(int i = 1; i <= n; i++){
            while(a[i]<t){
                a[i] += b[i];
            }
            if(mmin > a[i]){
                mmin = a[i]; id = i;
            }
        }
        cout<<id<<'
    ';
        return 0;
    }
    
  • 相关阅读:
    PHP操作MYSQL数据库
    微信DLL劫持反弹shell复现
    ERROR Invalid options in vue.config.js: "baseUrl" is not allowed
    求曲线y=lnx在区间(2,6)内的一条切线,使得该切线与直线x=2,x=6及曲线y=lnx所围成的图形的面积最小。
    CentOS、Ubuntu、Debian三个linux比较异同
    jpa模糊查询(表中的某些数据)
    jpa查找数据库最新一条消息
    在@Data注释lombok上使用继承警告等于/ hashCode(Warning equals/hashCode on @Data annotation lombok with inheritance)
    git基本操作
    远程分支git换地址了,本地重新关联
  • 原文地址:https://www.cnblogs.com/gwj1314/p/12300281.html
Copyright © 2011-2022 走看看