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 ...
随机推荐
- JavaScript笔记——DOM的操作
节点及其类型 在JavaScript中,节点分为三种: 元素节点:HTML标签元素. 属性节点: 元素的属性, 可以直接通过属性的方式来操作. 文本节点: 是元素节点的子节点, 其内容为文本. 在什么 ...
- apache 不解析 php
apache 不解析php 1.找到: AddType application/x-gzip .gz .tgz在其下面添加: AddType application/x-httpd-php .php ...
- PHP_File文件操作简单常用函数
php测试文件 <?php header("Content-type:text/html;charest=utf-8");$fileDir='Upload/File/cont ...
- Android 4 学习(14):Internet Resources
参考<Professional Android 4 Development> 使用Internet资源 打开URI String myFeed = getString(R.string.m ...
- 手机自带输入法emoji表情的输入,提交及显示——前端解决方案
体验更优排版请移步原文:http://blog.kwin.wang/programming/emoji-transform-commit.html 之前就遇到过需要前端支持用户输入并提交emoji表情 ...
- MySQL备份还原之三使用xtrabackup
1 xtrabackup安装 1)解压源码包 tar -xzvf percona-xtrabackup-2.1.7.tar.gz 2)安装perl环境(DBI/DBD) yum install per ...
- CentOS-6.4 编译安装ffmpeg加x264以及rtmp
CentOS 6.4-64位下编译ffmpeg几个简单步骤: 1.编译前环境准备: 2.下载源码: 3.编译,安装: ----------------------------------------- ...
- Python基础学习四 文件操作(二)
####读取文件#### with open('goods_info.txt', 'r', encoding='utf-8') as f: f.seek(0) # 注意指针位置 goods_info ...
- 14-EasyNetQ之用Future Publish发布预定中事件
很多商业流程需要事件在未来的时间按照预定时间发布.例如,在初次与客户接触后,可以在未来某个时间去电话回访客户.EasyNetQ可以用它的Future Publish功能帮你实现这个功能.举例:这里我们 ...
- Redis搭建(三):哨兵模式
一.sentinel介绍 Redis 2.8中提供了“哨兵”工具来实现自动化的系统监控和故障恢复功能. Redis 2.6 版也提供了哨兵工具,但此时的哨兵是1.0版,存在非常多的问题,任何情况下都不 ...