Business Center

Time Limit: 1000ms
Memory Limit: 65536KB

This problem will be judged on PKU. Original ID: 3863
64-bit integer IO format: %lld      Java class name: Main

 
International Cyber Police Corporation (ICPC) had built a new mega-tall business center to host its headquarters and to lease some space for extra profit. It has so many floors, that it is impractical to have a separate button in each of its m elevator cars for each individual floor. Instead, each elevator car has just two buttons. One button in i-th elevator car makes it move up ui floors, the other makes it move down di floors. The business center is so high, that we can ignore its height for this problem (you will never reach the top floor), but you cannot go below the ground floor. All floors are numbered by integer numbers starting from zero, zero being the ground floor. 
You start on the ground floor of the business center. You have to choose one elevator car out of m to ride on. You cannot switch elevators cars after that. What is the lowest floor above the ground floor you can get to after you press elevator car buttons exactly n times?

 

Input

The first line of the input file contains two integer numbers n and m (1 <= n <= 1 000 000, 1 <= m <= 2 000) - the number of button presses and the number of elevator cars to choose from. The following m lines describe elevator cars. Each line contains two integer numbers ui and di (1 <= ui, di <= 1 000).

 

Output

Write to the output file a single positive integer number - the number of the lowest floor above ground floor that can be reached by one of m elevators after pressing its buttons exactly n times.

 

Sample Input

10 3
15 12
15 4
7 12

Sample Output

13

Source

 
解题:直接搞呗。。貌似要求必须至少上一次
 #include<bits/stdc++.h>
using namespace std;
typedef long long LL;
LL n,m,u,d,ret;
void check() {
LL tmp = (n*d+u+d)/(u+d);
ret = min(ret,(u+d)*tmp - n*d);
}
int main() {
ios::sync_with_stdio(false);
cin>>n>>m;
ret = INT_MAX;
while(m--) {
cin>>u>>d;
check();
}
cout<<ret<<endl;
return ;
}

POJ 3863 Business Center的更多相关文章

  1. UVa 1648 (推公式) Business Center

    题意: 有一种奇怪的电梯,每次只能向上走u个楼层或者向下走d个楼层 现在有m个这种电梯,求恰好n次能够到达的最小楼层数(必须是正数),最开始默认位于第0层. 分析: 假设电梯向上走x次,则向下走n-x ...

  2. BZOJ 4159 [Neerc2009]Business Center

    思路 简单的模拟,答案就是\(min\{(\lfloor\frac{d\times n}{u+d}\rfloor+1)\times(u+d)-d\times n\}\) 代码 #include < ...

  3. UVA 1648 Business Center

    https://vjudge.net/problem/UVA-1648 设上升x层,列个方程解出来,再把x带回去 #include<cmath> #include<cstdio> ...

  4. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

  5. 2015 UESTC Winter Training #10【Northeastern Europe 2009】

    2015 UESTC Winter Training #10 Northeastern Europe 2009 最近集训都不在状态啊,嘛,上午一直在练车,比赛时也是刚吃过午饭,状态不好也难免,下次比赛 ...

  6. Angular material mat-icon 资源参考_Places

    ul,li>ol { margin-bottom: 0 } dt { font-weight: 700 } dd { margin: 0 1.5em 1.5em } img { height: ...

  7. Inventor2018专业版软件安装激活教程

    如果你安装的是Autodesk Inventor Professional 2018,那么序列号为:666-69696969,产品密钥为:797J1, 如果你安装的是Autodesk Inventor ...

  8. OptaPlanner 7.32.0.Final版本彩蛋 - SolverManager之异步求解

    因为工作和其它原因,很长一段时间没有出新的.关于OptaPlanner的文章了,但工余时间并没有停止对该引擎的学习.与此同时Geoffrey大神带领的KIE项目团队并没有闲下来,尽管在工业可用性.易用 ...

  9. POJ 2774 Long Long Message 后缀数组

    Long Long Message   Description The little cat is majoring in physics in the capital of Byterland. A ...

随机推荐

  1. <%=%>、<%%>、<%@%>、<%#%>的区别

    1.<%= %> 里面放变量名,获取后台的变量值,直接输入变量到页面上,里面放的变量名,未经过encode eg: 后台: seession["ab"]=ab; 前台: ...

  2. HDU 1704 Rank【传递闭包】

    解题思路:给出n个选手,m场比赛,问不能判断胜负的询问最多有多少种 用传递闭包即可 但是如果直接用3重循环会超时 在判断d[i][j]=d[i][k]||d[k][j]是否连通的时候 可以加一个if语 ...

  3. SQL之子查询

    子查询概念:把一个查询的结果在另一个查询中使用就叫做子查询 1.子查询作为条件时 当我们使用子查询作为条件时,若子查询返回值为多个,则会报以下错误: "子查询返回的值不止一个.当子查询跟随在 ...

  4. Quartz任务调度 服务日志+log4net打印日志+制作windows服务

    引言 现在许多的项目都需要定时的服务进行支撑,而我们经常用到的定时服务就是Quartz任务调度了.不过我们在使用定时Job进行获取的时候,有时候我们就需要记录一下自定义的日志,甚至我们还会对执行定时J ...

  5. PHP读xml、写xml(DOM方法)

    <?php /** * 读取的xml的格式 * <urlset> * <url> * <loc>http://www.51buy.com/0.html< ...

  6. 题解 P3128 【[USACO15DEC]最大流Max Flow】

    此类型题目有两种比较常见的做法:树链剖分和树上差分. 本题有多组修改一组询问,因此树上差分会比树链剖分优秀很多. 这里两种方法都进行介绍. 树链剖分和树上差分的本质都是将一颗树转换为一个区间,然后进行 ...

  7. 6.5.2 C# 中的函数组合

    6.5.2 C# 中的函数组合 C# 中的函数组合是可能的.但使用非常有限,这是部分是由于在 C# 中散应用不能非常easy使用.但更重要的是,由于大多数操作是用成员来写的.而不是函数.但我们至少能够 ...

  8. mysql-数据库维护

    一.备份数据 1.使用mysqldump命令备份:前提:musql的版本必须一致. mysqldump -u username -p  --default -character-set=gbk dbn ...

  9. 安卓开发,adb shell 调试sqlite3数据库

    安卓开发,adb shell 调试sqlite3数据库 在安卓中创建了sqlite3数据库,想要调试怎么办? 通过adb shell来进行查看. 第一步,将adb加入到系统变量中. 这样就可以在命令行 ...

  10. matplotlib 可视化 —— 移动坐标轴(中心位置)

    通常软件绘图,包括 matlab.python 的 matplotlib,默认都是将坐标轴置于画布(figure)的最下侧(x 轴),最左侧(y 轴),也即将坐标原点置于左下角.而我们自己理解数学,以 ...