码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2020-01-13 21:58:50      阅读:96      评论:0      收藏:0      [点我收藏+]

标签:之间   nbsp   and   cout   +=   put   数据   namespace   大于   

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

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

 如果有多种可能,输出一种

Output

乘到的公交车的路线编号。

///

题目其实说的已经很明显了,但就是不会,太菜了,呜呜呜呜。(为什么我会想到给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;
}

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

标签:之间   nbsp   and   cout   +=   put   数据   namespace   大于   

原文地址:https://www.cnblogs.com/Aracne/p/12189266.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!