Codeforces Round #551 (Div. 2)A. Serval and Bus
1 second
256 megabytes
standard input
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.
The first line contains two space-separated integers nn and tt (1≤n≤1001≤n≤100 , 1≤t≤1051≤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 (1≤si,di≤1051≤si,di≤105 ) — the time when the first bus of this route arrives and the interval between two buses of this route.
Print one number — what bus route Serval will use. If there are several possible answers, you can print any of them.
2 2
6 4
9 5
1
5 5
3 3
2 5
5 6
4 9
6 1
3
3 7
2 2
2 3
2 4
1
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时间就会再来一班,问你小孩会上哪辆车,如果有多辆符合,则任意输出一辆;
我们暴力算,面向数据编程;
我们先判断车第一次到能不能符合条件,不能的话再不断去加后面的时间,直到符合条件
代码如下:
#include<iostream>
using namespace std; int n ;
int chil;
struct buss{
int first;
int t;
}bus[];
int flag = ;
int tot[];
int main()
{
cin>>n;
cin>>chil;
for(int i = ; i <= n ;i++)
{
cin>>bus[i].first>>bus[i].t;
}
for(int i = ; i <= n ;i++)
{
tot[i] += bus[i].first;
if(tot[i]<chil) //先看车第一次来是否符合条件,不符合条件则不断加
{
while()
{
tot[i] +=bus[i].t;
if(tot[i]>=chil)
break;
}
}
}
int min = 0x3f3f3f3f;
int num;
for(int i = ; i<= n ;i++)
{
if(tot[i]-chil<min) //找最接近小孩时间的车
{
min = tot[i]-chil;
num = i ;
} } cout<<num;
}
Codeforces Round #551 (Div. 2)A. Serval and Bus的更多相关文章
- Codeforces Round #551 (Div. 2) D. Serval and Rooted Tree (树形dp)
题目:http://codeforces.com/contest/1153/problem/D 题意:给你一棵树,每个节点有一个操作,0代表取子节点中最小的那个值,1代表取子节点中最大的值,叶子节点的 ...
- Codeforces Round #551 (Div. 2)B. Serval and Toy Bricks
B. Serval and Toy Bricks time limit per test 1 second memory limit per test 256 megabytes input stan ...
- Codeforces Round #551 (Div. 2) D. Serval and Rooted Tree (树形dp)
题目链接 题意:给你一个有根树,假设有k个叶子节点,你可以给每个叶子节点编个号,要求编号不重复且在1-k以内.然后根据节点的max,minmax,minmax,min信息更新节点的值,要求根节点的值最 ...
- Codeforces Round #551 (Div. 2) E. Serval and Snake (交互题)
人生第一次交互题ac! 其实比较水 容易发现如果查询的矩阵里面包含一个端点,得到的值是奇数:否则是偶数. 所以只要花2*n次查询每一行和每一列,找出其中查询答案为奇数的行和列,就表示这一行有一个端点. ...
- Codeforces Round #551 (Div. 2) F. Serval and Bonus Problem (DP/FFT)
yyb大佬的博客 这线段期望好神啊... 还有O(nlogn)FFTO(nlogn)FFTO(nlogn)FFT的做法 Freopen大佬的博客 本蒟蒻只会O(n2)O(n^2)O(n2) CODE ...
- 【Codeforces】Codeforces Round #551 (Div. 2)
Codeforces Round #551 (Div. 2) 算是放弃颓废决定好好打比赛好好刷题的开始吧 A. Serval and Bus 处理每个巴士最早到站且大于t的时间 #include &l ...
- Codeforces Round #551 (Div. 2) A-E
A. Serval and Bus 算出每辆车会在什么时候上车, 取min即可 #include<cstdio> #include<algorithm> #include< ...
- Codeforces Round #551 (Div. 2) A~E题解
突然发现上一场没有写,那就补补吧 本来这场应该5题的,结果一念之差E fail了 A. Serval and Bus 基本数学不解释,假如你没有+1 -1真的不好意思见人了 #include<c ...
- C. Serval and Parenthesis Sequence 【括号匹配】 Codeforces Round #551 (Div. 2)
冲鸭,去刷题:http://codeforces.com/contest/1153/problem/C C. Serval and Parenthesis Sequence time limit pe ...
随机推荐
- JDBC概述及连接数据库
一.JDBC简介: JDBC(Java Data Connectivity,java数据库连接)是一种用于执行sql语句的JavaAPI,可以为多种关系数据库提供统一访问,它由一组用Java语言编写 ...
- leetcode908
int smallestRangeI(vector<int>& A, int K) { int min = INT_MAX; int max = INT_MIN; for (aut ...
- ubuntu12上部署Django1.8.4+uwsgi+nginx超级详细流程配置到云服务器
环境: 系统:ubuntu12,系统自带默认有python2.7 框架:Django1.8.4,需要python2.7以上才能支持 前言: 用户浏览器发送http请求->nginx(静态文件 ...
- day63-webservice 01.cxf介绍
CXF功能就比较强了.CXF支持soap1.2.CXF和Spring整合的非常密切.它的配置文件基本就是Spring的配置文件了.CXF是要部署在服务器才能用的.CXF得放到Web容器里面去发布.CX ...
- 07-Location之正则匹配
大网站专门有自己的图片服务器,起码也得单独放一个目录里面. 淘宝网有些图片开启了防盗链(即使是小图片,也不让你下载,真小气).163新闻可以下载. 用正则匹配uri中的image,就是说你的uri中到 ...
- python子进程模块subprocess详解与应用实例 之一
subprocess--子进程管理器 一.subprocess 模块简介 subprocess最早是在2.4版本中引入的. subprocess模块用来生成子进程,并可以通过管道连接它们的输入/输出/ ...
- datatables01 安装、数据源、选中行事件、新增一行数据、删除一行数据
1 安装 1.1 引入必要文件 要在项目中使用datatables需要引入三个文件 >DataTables CSS >jQuery >DataTables JS <!-- Da ...
- CF519E A and B and Lecture Rooms
最近很颓……难题想不动……水题写不对,NOIP怕是
- SQLServer跨库查询--分布式查询
出处:http://www.cnblogs.com/doosmile/archive/2012/03/16/2400646.html --用openrowset连接远程SQL或插入数据 --如果只是临 ...
- Requests接口测试(四)
Python序列化和反序列化 啥是序列化?啥是反序列化?这两个词听起来优点高大上的意思,其实呢不然,很简单的可以理解为: 序列化:将python的数据对象编码转换为json格式的字符串 反序列化:将j ...