Codeforces1153A-Serval and Bus(数学)

2023-05-16

原题链接:http://codeforces.com/contest/1153/problem/A

题目原文:

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 (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.

Output

Print one number — what bus route Serval will use. If there are several possible answers, you can print any of them.

Examples

input

Copy


2 2
6 4
9 5
  

output

Copy


1
  

input

Copy


5 5
3 3
2 5
5 6
4 9
6 1
  

output

Copy


3
  

input

Copy


3 7
2 2
2 3
2 4
  

output

Copy


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.

题目大意:

         Serval要去公交站台,已知 t min 到达站台,n班公交车,a min 时到达站台,之后每 b min 一辆,Serval每次到站后选择第一辆公交乘坐,问是第几辆。

解题思路:

        对应的每一班只要求出等待时间即可,暴力法可以过,但仔细想想,其实通过简单的除余方法就可算出,毕竟每 b min 一辆车很容易让人想到跟MOD有关。

        if (t > a)  wait = ((a - t) % b + b) % b;
        else  wait = a - t;

这里一个负数除余为正的技巧 ((-x) % MOD + MOD) % MOD

AC代码:

#include <cstdio>
using namespace std;

const int INF = 0x3f3f3f3f;
 
int main()
{
	int n, t, i, minv, minid, a, b, v;
	while (scanf("%d%d", &n, &t) != EOF)
	{
		minid = INF;
		minv = INF;
		for (i = 1; i <= n; i++)
		{
			scanf("%d%d", &a, &b);
			if (t > a) v = ((a - t) % b + b) % b;
			else v = a - t;
			// printf("%d\n", v);
			if (v < minv)
			{
				minv = v;
				minid = i;
			}
		}
		printf("%d\n", minid);
	}
	return 0;
}

 

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

Codeforces1153A-Serval and Bus(数学) 的相关文章

随机推荐

  • 通俗易懂--逻辑回归算法讲解(算法+案例)

    标题 1 逻辑回归 Logistic Regression 1 1逻辑回归与线性回归的关系1 2损失函数1 3多分类问题 one vs rest 1 4逻辑回归 LR 的一些经验1 5LR的应用1 6Python代码实现 寻觅互联网 xff
  • 8: dist_train.sh: Bad substitution的解决

    问题 xff1a 解决 xff1a 用bash bash dist train span class token punctuation span sh configs span class token operator span pvt
  • pyqt 设置QPixmap透明度

    span class token comment 获得含有透明度的QPixmap span span class token comment param filePath 图片路径 opacity 透明度 0 255 越小越透明 span
  • 挂载时提升未知的文件系统类型“LVM2_member”

    问题排查 xff0c 检查是该模块是否被做成了pv span class token punctuation span root 64 localhost home span class token punctuation span spa
  • RestTemplate和Feign的区别

    文章目录 1 远程调用方法 xff08 RestTemplate和Feign xff09 1 RestTemplate简单的远程调用原型2 Feign远程调用 1 远程调用方法 xff08 RestTemplate和Feign xff09
  • PostgreSQL创建物化视图并刷新

    1 创建物化视图 视图hnqyhxv person CREATE MATERIALIZED VIEW hnqyhxv person TABLESPACE sys default as SELECT FROM E PRI PERSON WHE
  • java实现判断当前时间,是否在指定时间范围

    目录 文章目录 java实现判断当前时间 xff0c 是否在三月的最后一个星期日到十月的最后一个星期六1 问题提出2 问题解决 java实现判断当前时间 xff0c 是否在三月的最后一个星期日到十月的最后一个星期六 1 问题提出 事情是这样
  • 记一次activiti审批意见字段乱码问题

    目录 文章目录 记一次activiti审批意见字段乱码问题问题描述解决思路1 数据源连接配置问题2 检查数据库存储字段是否乱码3 查看部署环境的编码4 程序启动命令直接指定编码方式 记一次activiti审批意见字段乱码问题 问题描述 项目
  • KEIL MDK平台 S3C2440 汇编语言软件仿真

    KEIL MDK平台 S3C2440 汇编语言软件仿真 KEIL MDK平台 S3C2440 汇编语言软件仿真建立工程 xff0c 编辑汇编语言程序编译链接源程序调试博客同款例程https download csdn net downloa
  • matlab 语法_MATLAB中的语法

    matlab 语法 The syntax is the method by which the programmer give various commands to the system or the software These com
  • 什么是SSR/SSG/ISR?如何在AWS上托管它们?

    概述 在这篇文章中 xff0c 我们将讨论如何在AWS上运行SSR SSG ISR以及App Runner的魅力 内容 我们将首先分别解释传统和现代网络应用 接下来 xff0c 我们将介绍如何在AWS上托管SSR SSG ISR 传统网络应
  • 一篇让你上手mysql安装以及my.ini配置

    mysql目前已经作为我们常用的数据库了 xff0c 今天我们学习来安装一下它 1 下载 从官网上下载安装包 xff08 也可以公众号回复mysql可以获取 xff09 https dev mysql com downloads mysql
  • ESP8266型号、下载、接线、烧录等怕忘总结

    ESP8266型号 下载 接线 烧录等怕忘总结 1 不同模块参数 下载接线等 xff08 1 xff09 ESP01 xff08 2 xff09 ESP01S xff08 3 xff09 ESP07 xff08 4 xff09 ESP07S
  • github下载慢

    方法一 xff1a 从GitHub下载文件一直非常慢 xff0c 查看下载链接发现最终被指向了Amazon的服务器 xff0c 下载地址是 http github cloud s3 amazonaws com xff0c 从国内访问Amaz
  • 再次安装Arch Linux!(Vmware,KDE\Gnome桌面,EFI/BIOS引导,双系统配置)更新时间2018/11/11

    1 下载Arch Linux镜像 下载地址 xff1a https xff1a www archlinux org download 可以看到一个磁力一个种子 xff0c 任意下载一个并使用支持的下载软件进行镜像的下载 2 1 xff08
  • ozone调试

    对于keil编译的工程没法用gdb调试 xff08 我没发现方法 xff09 xff0c 那就用Ozone调试 xff0c 官网 https www segger com products development tools ozone j
  • pat1068

    对于计算机而言 xff0c 颜色不过是像素点对应的一个 24 位的数值 现给定一幅分辨率为 M N 的画 xff0c 要求你找出万绿丛中的一点红 xff0c 即有独一无二颜色的那个像素点 xff0c 并且该点的颜色与其周围 8 个相邻像素的
  • windows7系统下如何升级powershell(2.0升级到3.0版本)

    最近在使用vagrant命令时提示2 0的版本不支持需要升级powershell操作如下 查看本机powershell版本号 开始 运行 xff0c 输入powershell进入命令行窗口 在命令行中输入 PSVersionTable PS
  • python+pytesseract 中文识别

    继写了第一篇 包含验证码识别的自动化登录脚本后在一次与朋友聊天中谈到中文识别 想起Tesseract OCR是有这个包的 xff0c 然后我就搞了搞 coding 61 utf 8 from PIL import Image import
  • Codeforces1153A-Serval and Bus(数学)

    原题链接 xff1a http codeforces com contest 1153 problem A 题目原文 xff1a A Serval and Bus time limit per test 1 second memory li