A. Serval and Bus

2023-05-16

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.

思路:直接把所有的时间都弄到出发时间相等或之后,然后暴力一遍就OK

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<iostream>
#include<algorithm>
#include<map>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<string>
#define ll long long
using namespace std;

struct node {
	int x, y;
}S[100005];

int main() {
	int n, t;
	while (cin >> n >> t) {
		for (int i = 0; i < n; i++) {
			cin >> S[i].x >> S[i].y;
		}
		int flag = 0;
		int min = 1000050;
		int position = 0;
		while (1) {//先前思路错误,这个while没必要
			for (int i = 0; i < n; i++) {
				if (S[i].x == t) {
					flag = 1;
					cout << (i+1) << endl;
					break;
				}
			}
			if (flag == 1) {
				break;
			}
			for (int i = 0; i < n; i++) {
				while (1) {
					if (S[i].x < t) {
						S[i].x = S[i].x + S[i].y;
					}
					else {
						break;
					}
				}
			}
			for (int i = 0; i < n; i++) {
				if (S[i].x - t < min) {
					min = S[i].x - t;
					position = i + 1;
				}
			}
			if (min != 1000050) {
				cout << position << endl;
				break;
			}
		}

	}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

A. Serval and Bus 的相关文章

随机推荐

  • latex 字符上一横,箭头等显示方式

    a bar a a 横线 a
  • Java Web小案例:查询城市天气

    一 解决思路 1 首先获取泸州的城市代码 在返回的数据里 xff0c 第一项的ref值就是泸州的城市代码 xff1a 101271001 2 利用国家气象局提供的接口访问泸州的天气信息 二 准备工作 学会如何在Java程序里解析json 准
  • 最大矩形面积——单调栈

    问题描述 给一个直方图 xff0c 求直方图中的最大矩形的面积 例如 xff0c 下面这个图片中直方图的高度从左到右分别是2 1 4 5 1 3 3 他们的宽都是1 xff0c 其中最大的矩形是阴影部分 Input 输入包含多组数据 每组数
  • Week 14 B——Q老师与十字叉

    Q老师与十字叉 Q老师 得到一张 n 行 m 列的网格图 xff0c 上面每一个格子要么是白色的要么是黑色的 Q老师认为失去了 十字叉 的网格图莫得灵魂 一个十字叉可以用一个数对 x 和 y 来表示 其中 1 x n 并且 1 y m 满足
  • Week 14 C - Q老师的考验

    Q老师的考验 Q老师 对数列有一种非同一般的热爱 xff0c 尤其是优美的斐波那契数列 这一天 xff0c Q老师 为了增强大家对于斐波那契数列的理解 xff0c 决定在斐波那契的基础上创建一个新的数列 f x 来考一考大家 数列 f x
  • Week 14 E - Q老师度假

    Q老师度假 忙碌了一个学期的 Q老师 决定奖励自己 N 天假期 假期中不同的穿衣方式会有不同的快乐值 已知 Q老师 一共有 M 件衬衫 xff0c 且如果昨天穿的是衬衫 A xff0c 今天穿的是衬衫 B xff0c 则 Q老师 今天可以获
  • python-读取文件夹下的txt文件,读出矩阵数据,转置操作后存入新的txt文件

    在所作项目中需要将主行的矩阵变成主列的矩阵 即 1 1 写成 1 2 2 2 1 2 读入的数据为如下格式 xff1a 文件夹下的文件如下所示 xff1a 代码转置后的格式如下所示 xff1a 代码可以遍历文件夹下所有文件 xff0c 并且
  • Linux 下安装 sonarQube

    sonarQube详细介绍看我这篇文章 xff1a 代码分析工具 SonarQube 单椒煜泽的博客 CSDN博客 代码分析工具 SonarQube下载地址 xff1a Download SonarQube Windows环境从零搭建Son
  • Matlab2017a之前版本的 MATLAB MinGW-w64 C/C++ Compiler4.9.2下载

    对于Matlab R2015b up to R2017a xff0c 使用MinGW 4 9 2 TDM GCC 对于Matlab R2017b MinGW 5 3 Matlab R2015b up to R2017a 下载地址 xff1a
  • Apache CXF框架简介

    Apache CXF框架是一个开源的Web Services框架 xff0c 它来源于两个开源项目 ObjectWeb Celtix ESB产品 和Codehaus XFire SOAP堆栈软件 Apache CXF提供了对JAX WS规范
  • 寻找身高相近的小朋友

    小明今年升学到了小学1年纪 来到新班级后 发现其他小朋友身高参差不齐 然后就想基于各小朋友和自己的身高差 对他们进行排序 请帮他实现排序 输入描述 第一行为正整数 h和n 0 lt h lt 200 为小明的身高 0 lt n lt 50
  • 数字涂色 疫情过后希望小学终于又重新开学了

    注意 答案仅作为参考 实际考试中下列代码通过用例100 但不代表最优解 疫情过后希望小学终于又重新开学了 3年2班开学第一天的任务是 将后面的黑板报重新制作 黑板上已经写上了N个正整数 同学们需要给这每个数分别上一种颜色 为了让黑板报既美观
  • 九宫格按键输入法

    注意 答案仅作为参考 实际考试中下列代码通过用例100 但不代表最优解 九宫格按键输入 输出显示内容 有英文和数字两个模式 默认是数字模式 数字模式直接输出数字 英文模式连续按同一个按键会依次出现这个按键上的字母 如果输入 或者其他字符 则
  • 斗地主之顺子

    注意 答案仅作为参考 实际考试中下列代码通过用例100 但不代表最优解 在斗地主扑克牌游戏中 扑克牌由小到大的顺序为 3 4 5 6 7 8 9 10 J Q K A 2 玩家可以出的扑克牌阵型有 单张 对子 顺子 飞机 炸弹等 其中顺子的
  • 高矮个子排队

    注意 答案仅作为参考 实际考试中下列代码通过用例100 但不代表最优解 现在有一队小朋友 他们高矮不同 我们以正整数数组表示这一队小朋友的身高 如数组 5 3 1 2 3 我们现在希望小朋友排队 以 高 矮 高 矮 顺序排列 每一个 高 位
  • java代码转python代码(需要手动调整)

    xff08 1 xff09 windows 环境安装工具 python版本 7 先下载antlr http www antlr3 org download antlr 3 1 3 tar gz 链接 https pan baidu com
  • 统计每个月兔子的总数

    题目描述 有一只兔子 从出生后第3个月起每个月都生一只兔子 小兔子长到第三个月后每个月又生一只兔子 假如兔子都不死 问每个月的兔子总数为多少 输入描述 输入int型表示month 输出描述 输出兔子总数int型 示例1 输入 9 输出 34
  • 字符串运用-密码截取

    题目描述 Catcher 是MCA国的情报员 他工作时发现敌国会用一些对称的密码进行通信 比如像这些ABBA ABA A 123321 但是他们有时会在开始或结束时加入一些无关的字符以防止别国破解 比如进行下列变化 ABBA gt 12AB
  • 吃火锅 入职后导师

    入职后导师会请你一起吃火锅 有m个菜品 你的手速是n 即吃完一道菜 要经过时间n才能再去夹菜 任一菜品下锅后 都需要经过对应时间才能熟 过时就不可口了 怎样可以吃到最多的可口的菜 输入 第1行 菜品数量m 手速n 第2 m行 每行两个数字
  • A. Serval and Bus

    outputstandard output It is raining heavily But this is the first day for Serval who just became 3 years old to go to th