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

A. Serval and Bus
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard 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 tt , and there are nn bus routes which stop at this station. For the ii -th bus route, the first bus arrives at time sisi minutes, and each bus of this route comes didi 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 nn and tt (1n1001≤n≤100 , 1t1051≤t≤105 ) — the number of bus routes and the time Serval goes to the station.

Each of the next nn lines contains two space-separated integers sisi and didi (1si,di1051≤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
Input
 
2 2
6 4
9 5
Output
 
1
Input
 
5 5
3 3
2 5
5 6
4 9
6 1
Output
 
3
Input
 
3 7
2 2
2 3
2 4
Output
 
1
Note

In the first example, the first bus of the first route arrives at time 66 , and the first bus of the second route arrives at time 99 , so the first route is the answer.

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

In the third example, buses of the first route come at times 22 , 44 , 66 , 88 , and so fourth, buses of the second route come at times 22 , 55 , 88 , and so fourth and buses of the third route come at times 22 , 66 , 1010 , and so on, so 11 and 22 are both acceptable answers while 33 is not.

 解题思路:这道题就是给你n个数据,小孩到达车站的时间;以及数据车第一次到车站的时间以及之后每个t时间就会再来一班,问你小孩会上哪辆车,如果有多辆符合,则任意输出一辆;

我们暴力算,面向数据编程;

我们先判断车第一次到能不能符合条件,不能的话再不断去加后面的时间,直到符合条件

代码如下:

 1 #include<iostream>
 2 using namespace std;
 3 
 4 
 5 int n ;
 6 int chil;
 7 struct buss{
 8     int first;
 9     int t;
10 }bus[105];
11 int flag = 0 ;
12 int tot[105];
13 int main()
14 {
15     cin>>n;
16     cin>>chil;
17     for(int i = 1 ; i <= n ;i++)
18     {
19         cin>>bus[i].first>>bus[i].t;
20     }    
21         for(int i = 1 ; i <= n ;i++)
22         {
23             tot[i] += bus[i].first;  
24             if(tot[i]<chil)   //先看车第一次来是否符合条件,不符合条件则不断加
25             {
26                 while(1)
27                 {
28                        tot[i] +=bus[i].t;
29                     if(tot[i]>=chil)
30                     break;
31                 }
32             }    
33         }
34         int min = 0x3f3f3f3f;
35         int num;
36         for(int i = 1 ; i<= n ;i++)
37         {
38             if(tot[i]-chil<min)   //找最接近小孩时间的车
39             {
40                 min = tot[i]-chil;
41                 num  = i ;
42             }
43         
44         }
45     
46     cout<<num;
47 }
原文地址:https://www.cnblogs.com/yewanting/p/10708144.html