POJ 3863 Business Center

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

Northeastern Europe 2009

解题:直接搞呗。。貌似要求必须至少上一次

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 typedef long long LL;
 4 LL n,m,u,d,ret;
 5 void check() {
 6     LL tmp = (n*d+u+d)/(u+d);
 7     ret = min(ret,(u+d)*tmp - n*d);
 8 }
 9 int main() {
10     ios::sync_with_stdio(false);
11     cin>>n>>m;
12     ret = INT_MAX;
13     while(m--) {
14         cin>>u>>d;
15         check();
16     }
17     cout<<ret<<endl;
18     return 0;
19 }

时间: 2024-11-05 20:40:19

POJ 3863 Business Center的相关文章

Trimble Business Center 3.60 Win64 1DVD+Altair.SimLab.14.1

Digital.Vision.Nucoda.v2015.3.020.Win64 1DVD  iMold v13 SP3 for SolidWorks 2011-2016 Win32_64 2CD  NI.LabVIEW.2015.SP1.v15.0.1.Win32_64 2DVD  Trimble Business Center 3.60 Win64 1DVD  CEI.Ensight.10.1.6d.GOLD.Windows.MacOSX64.Linux32_64 4DVD  Mathwork

poj 3863&amp;&amp;Gym - 101308B Business Center (水题/推公式)

题意:给你 m 个电梯,每个电梯有两个按钮, u 和 d ,分别代表上 u 层,和下 d 层,每一次你都从第0层开始做电梯,你可以按这个电梯按钮 m 次,假设楼层无限高,问你可以到达的最低楼层是多少,0层除外? 思路: 我们假设按 上走 x 次, 那么下走为 (n-x) 次 那么可以到达的楼层为 k = a*x - b*(n-x) 另上式等于0,我们可以得到当 x'= b*n/(a+b) 时为第0层 由于 x 必须为正整数,我们对 x' 向上取整,就得到可以到达的最低楼层 但是现在有一个漏洞,如

UVa 1648 (推公式) Business Center

题意: 有一种奇怪的电梯,每次只能向上走u个楼层或者向下走d个楼层 现在有m个这种电梯,求恰好n次能够到达的最小楼层数(必须是正数),最开始默认位于第0层. 分析: 假设电梯向上走x次,则向下走n-x次,则所到达的楼层为xu - (n-x)d ≥ 0 (u+d)x ≥ nd,x的最小值为 换句话说,如果nd % (u+d) == 0, x = nd / (u+d) 否则 x = nd / (u+d) + 1 考虑到不能停到0楼的条件:当nd % (u+d) == 0会出现这种情况,所以只能多上一

UVA 1648 Business Center

https://vjudge.net/problem/UVA-1648 设上升x层,列个方程解出来,再把x带回去 #include<cmath> #include<cstdio> #include<iostream> #include<algorithm> using namespace std; int u[2001],d[2001]; int main() { int n,m,ans,x; while(scanf("%d%d",&am

POJ 1859 The Perfect Symmetry &amp;&amp; POJ2526 Center of symmetry(思维题)

博客原文地址:http://blog.csdn.net/xuechelingxiao/article/details/40680981 POJ 1859 : The Perfect Symmetry 题目大意: 给你n个点的座标,你的任务是判断是否存在一个中心,使得这些点中心对称.一个点集有中心对称点的条件是,存在一个点s,对于每一个点p,都存在另一个点q使得p - s = s - q . 解题思路: 既然要找中间的点,那么对于中间的点,肯定会有两边对称的点,那么说,点集排序之后,先找到排序后的

@最新CAX/EDA/CFD/GIS/光学/化工/液压软件资源网

最新CAX/EDA/CFD/GIS/光学/化工/液压软件资源网 阳光软件园 所有软件资料都随时更新,急需软件可以去看看,基本上能找到你想要的! http://zhangqg.51.net http://cax2one.f3322.net e-mail: [email protected];[email protected];[email protected] 将以上任意链接连接起来输入IE 窗口即可进入网站 下面是一部分软件,更多软件在我们的软件列表,如需要请到列表中去找! ACTRAN v14

百家基于ACIS的软件ZWCAD.ZW3D.v2016.Beta3.Win32_64 2DVD

世界上已有数百家基于ACIS的软件ZWCAD.ZW3D.v2016.Beta3.Win32_64 2DVD     增加了三维功能和VBA支持的增强版本.中望CAD专业版除了具备中望CAD 2008版(标准版)的全部功能外,增加了支持三维实体的显示.编辑和建模及渲染,同时提供VBA的开发接口支持,客户可以方便的使用VB开发工具进行二次开发.中望CAD专业版是国内第一套以强大的二维设计为基础.同时融合基本三维设计功能的CAD解决方案,主要面对建筑.机械.家具和制造领域内以二维绘图为主,同时也用到部

最吸引人的地方在于弹性全新软件Aspalathosoft.Aspalathos.v2.1 1CD

最吸引人的地方在于弹性全新软件Aspalathosoft.Aspalathos.v2.1 1CD The.Foundry.Katana.v2.1v2.Linux64 1CD    KATANA可以产生非常复杂的分镜头,同时美术人员还能维持控制它的能力.KATANA是针对需要管理大量 资产的工作流程所设计的.一旦分镜头开始处理,就能夠允许资产进行更新.分享灯光设定,例如在分镜 头之前与序列间进行编辑,覆盖.允许你使用多个渲染器,指定不同pass之间的相依关系,针对特定分镜 头可以修改某个场景资产来

CAD-Earth.v4.0.5.AutoCAD.2007-2015 4CD

SafeTech.FE-Safe.v6.5.Windows-ISO 1DVD Trimble Business Center v3.21.Update.Only 1CD Amberg.TMS.Office.v1.1.0.10 1CD Bentley AutoPIPE Vessel V8i 33.02.02.04 1CD Siemens.NX.v9.0.3.Update.Only.Linux64 1DVD Bentley.RM.Bridge.Advanced.V8i.08.11.18.01 1CD