Codeforces Round #551 (Div. 2)A. Serval and Bus

给出n条路线公交车的到达时间以及发车间隔时间,路线编号为1~n,Alice在t时刻到达,求她最早可以上哪班车。Input第一行输入路线数n和Alice到达的时间t n,t(1≤n≤100,1≤t≤10e5)

 接下来n行,每行两个数字s和d(1≤s,d≤1e5),分别为该条路线首辆车到达的时间和两辆车之间的发车间隔

题目其实说的已经很明显了,但就是不会,太菜了,呜呜呜呜。(为什么我会想到给t%24啊。。。。。

数据量比较小,直接暴力了行了,注意的是需要将发车时间r加到刚好大于t的时候,再比较t-r的大小就可以了。

#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
const double PI=3.1415926535897931;
const long long sale=1e9+10;
const int MA= 1e7+10;
const int ma= 2*1e5+10;
const int few=1e3+10;
using namespace std;
//////////////////////////////////////////////
int main()
{
    int n,t;
    cin>>n>>t;
    long long sum=1e10;
    int ans;
    for(int i=0; i<n; i++)
    {
        int r,l;
        cin>>r>>l;
        while(r<t)
            r+=l;
        if(r-t<sum)
        {
            sum=r-t;
            ans=i+1;
        }
    }
    cout<<ans<<endl;
    return 0;
}
原文地址:https://www.cnblogs.com/Aracne/p/12189266.html