Codeforces A. Serval and Bus
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 ;
}
Codeforces A. Serval and Bus的更多相关文章
- 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 in ...
- Codeforces 1153D Serval and Rooted Tree (简单树形DP)
<题目链接> 题目大意: Serval拥有的有根树有n个节点,节点1是根. Serval会将一些数字写入树的所有节点.但是,有一些限制.除叶子之外的每个节点都有一个写入操作的最大值或最小值 ...
- Codeforces 1153F Serval and Bonus Problem [积分,期望]
Codeforces 思路 去他的DP,暴力积分多好-- 首先发现\(l\)没有用,所以不管它. 然后考虑期望的线性性,可以知道答案就是 \[ \int_0^1 \left[ \sum_{i=k}^n ...
- CodeForces 660B Seating On Bus
模拟. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #inc ...
- Codeforces Gym 101521A Shuttle Bus
题意:给定一个2*N的方格,从左上角开始走,有些格子不能走,问能否一次遍历所有能走的方格 在Gym上看到一场香港的比赛,很好奇就去看了一下,发现第一题很有趣,并且很水,似乎讨论一下奇偶性就行了,然后. ...
- Codeforces Round #436 C. Bus
题意:一辆车在一条路上行驶,给你路的总长度a,油箱的容量b,加油站在距离起点的距离f,以及需要走多少遍这条路k(注意:不是往返) 问你最少加多少次油能走完. Examples Input 6 9 2 ...
- $CF1153A\ Serval\ and\ Bus$
看大佬的代码都好复杂(不愧是大佬\(orz\) 蒟蒻提供一种思路 因为求的是最近的车对吧\(qwq\) 所以我们可以用一个\(while\)循环所以没必要去用什么 \(for...\) 至于这是\(d ...
- @codeforces - 1153F@ Serval and Bonus Problem
目录 @description@ @solution@ @accepted code@ @details@ @description@ 从一条长度为 l 的线段中随机选择 n 条线段,共 2*n 个线 ...
- 【Codeforces】Codeforces Round #551 (Div. 2)
Codeforces Round #551 (Div. 2) 算是放弃颓废决定好好打比赛好好刷题的开始吧 A. Serval and Bus 处理每个巴士最早到站且大于t的时间 #include &l ...
随机推荐
- dubbo之心跳机制
在网络传输中,怎么确保通道连接的可用性是一个很重要的问题,简单的说,在网络通信中有客户端和服务端,一个负责发送请求,一个负责接收请求,在保证连接有效性的背景下,这两个物体扮演了什么角色,心跳机制能有效 ...
- ElasticSearch安装---Windows环境
一.前提条件 已经安装了jdk 1.8 二.下载 中文官网: https://www.elastic.co/cn/ 中文官网下载: https://elasticsearch.cn/download/ ...
- gulp-css-spriter 雪碧图合并
相信做前端的同学都做过这样的事情,为优化图片,减少请求会把拿到切好的图标图片,通过ps(或者其他工具)把图片合并到一张图里面,再通过css定位把对于的样式写出来引用的html里面.gulp-css-s ...
- Yeoman+Bower+gulp web前端自动化工作流程(初级教程)
Yeoman包括了三个部分yo(脚手架工具).grunt/gulp(构建工具).bower(包管理器).听说gulp更容易上手,所以我就没用grunt而选的gulp 什么是开发流程? 在我看来一个完整 ...
- c++ STL queue:deque+优先队列
/* queue 模板类需要两个模板参数,一个是元素类型,一个容器类型,元素类型是必要的,容器类型是可选的,默认为deque队列 类型.一:定义queue(要有头文件#include <qu ...
- laravel的Validation检索验证错误消息
基本用法 处理错误消息 错误消息和视图 可用的验证规则 有条件地添加规则 自定义错误消息 自定义验证规则 基本用法 Laravel提供了一个简单.方便的工具,用于验证数据并通过validation类检 ...
- Alan Walker MV 合辑01 by defender
Alan Walker MV合辑 出来啦! 百度网盘下载地址: 链接:https://pan.baidu.com/s/10WSool70XBe_8tJOae8V-w 提取码:uckq 地址查看 Mi ...
- 在电脑上用chrome浏览器调试android手机里的网页代码时,无法看到本地加载的js文件
在需要调试的js文件最顶部加上代码就可以看到了: console.log('haha'); debugger;
- hzq84621巨佬的语录
摘自诸中培训讲图论时: 1.光图论考不出什么东西,一般作为DP的附庸出现. 2.如果不是骗骗不承认SPFA的外国人,一般能用dij就用dij. 3.那个东西(指bellman-ford)除了判负环没什 ...
- Web 开发人员推荐的通用独立 UI 组件
现代 Web 开发在将体验和功能做到极致的同时,对于美观的追求也越来越高.在推荐完图形库之后,再来推荐一些精品的独立 UI 组件.这些组件可组合在一起,形成美观而交互强大的 Web UI . 给 We ...