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代码如下:

 #include"iostream"
#include"algorithm"
#include"cstdio"
#include"cstring"
using namespace std;
int a[],b[],i,j,m,n,t,;
int main(){
while(cin>>n>>t){
int min=;
memset(a,,sizeof(a));
memset(b,,sizeof(b));
for(i=;i<n;i++){
scanf("%d %d",&a[i],&b[i]);
}
for(i=;i<n;i++){
while(a[i]<t){
a[i]+=b[i];
}
if(min>a[i]){
min=a[i];
m=i;
}
}
cout<<m+<<endl;
}
return ;
}

最新文章

  1. 解决Android Studio 无法显示Layout视图问题
  2. 5-4 bash脚本编程之三 条件判断及算术运算
  3. c语言经典算法——查找一个整数数组中第二大数
  4. Stack与Queue
  5. 怎样防止重复发送 Ajax 请求?
  6. 增加Xss过滤步骤
  7. N个数全排列的非递归算法
  8. 【20160924】GOCVHelper MFC增强算法(1)
  9. hdu 2053 Switch Game 水题一枚,鉴定完毕
  10. STL——sort函数简介
  11. Linux read语法及浅析
  12. iOS基础 - XML &amp; JSON
  13. AFNetworking封装思路简析
  14. bzoj4828 [Hnoi2017]大佬
  15. 简单bmp图片处理工具——python实现
  16. ubuntu下发布asp.net core并用nginx代理之旅
  17. MySQL 开发实践 8 问,你能 hold 住几个?
  18. vim配置(使用Vundle)
  19. GoLang函数参数的传递练习
  20. 1、用datetimepicker插件实现限定时间范围的选择 2、时间插件实现默认当天的时间和只能选择小于今天的日期

热门文章

  1. Codeforces Round #616 (Div. 2) C. Mind Control
  2. 854. Floyd求最短路(模板)
  3. 百度的Ueditor在VS2015/VS2010中配置需注意的地方
  4. BZOJ3932 CQOI2015 任务查询系统 - 主席树,离散化
  5. Oracle VM VirtualBox - VBOX_E_FILE_ERROR (0x80BB0004)
  6. C语言面试题22. 链表中倒数第k个节点
  7. Jmeter-文件目录
  8. 使用ScrollRect制作翻页
  9. 数据从mmsql导入mysql
  10. 洛谷P1028 数的计算