poj 3863 Business Center
来源:互联网 发布:天国王朝知乎 编辑:程序博客网 时间:2024/05/21 06:11
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
Thefirstlineoftheinputfilecontainstwointegernumbers nandm(1 ≤ n ≤ 1000000, 1 ≤ m ≤ 2000)—
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 ≤ 1000).
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 and output
business.in business.out
10 3 13
15 12
15 4
7 12
题意:给你好多电梯,每个电梯只有两个按钮,上a层和下b层,问选一个电梯,经过n次按按钮,能到达的最低楼层
思路:刚开始写的时候一直在第八组wa,后来随便改了改竟然过了,赛后有好好看了一下题意,原来是不能到达0层楼的,比赛的时候竟然改过了也是神奇,这个题直接就可以得答案不需要二分查找,
题目分析:设上升次数w为x ,则x*u-(n-x)*d>=0 解得:x>=n*d/(u+d);当能够整除时:在最终停在u+d,不过能够时停在
(n*d/(u+d)+1)*(u+d)-n*d;
ac代码:
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main()
{
//freopen("business.in","r",stdin);
//freopen("business.out","w",stdout);
int n,m,a,b,minn,t;
while(cin>>n>>m)
{
minn=1000000000;
for(int i=1;i<=m;i++)
{
cin>>a>>b;
if((b*n)%(a+b)==0)
t=a+b;//由于不能到0层所以需要加一层往上的减一层往下的正好多了a+b
else
{
int k=(b*n)/(a+b)+1;
t=a*k-b*(n-k);
}
minn=min(t,minn);
}
cout<<minn<<endl;
}
return 0;
}
- poj 3863Business Center
- poj 3863 Business Center
- Business Center
- Business Center
- Business Intelligence Center
- poj3863 Business Center 贪心
- 4159: [Neerc2009]Business Center
- B. Business Center
- [POJ3863]Business Center
- UVA 1648(p346)----Business Center
- uva 1648 Business Center 简单数学
- uva 1648 Business Center 数学+二分
- 基于Flash的Demo: BlackBerry Business Solution Demo Center
- When Should Your Business Consider Data Center Outsourcing?
- Oracle E-Business Suite Release 12.2 Information Center - Manage
- business
- business
- Trimble.Business.Center.v3.90.6369.58741 Trimble TILOS v9.0+TILOS
- IE无法打开网页的常见原因及解决
- 安卓移动逆向(二)
- 51nod 1384 全排列
- oracle中varchar(N)和varchar(N char)的区别
- inflate函数使用总结
- poj 3863 Business Center
- JZOJ1268.【USACO题库】2.3.3 Zero Sum和为零
- Vicarious说,现在的深度学习都是渣渣--转自微信
- Android Studio 技巧之【Join Lines and Literals】
- vim 快捷键
- poj1631 Bridging signals
- hdu1097 A hard puzzle
- hdu 1166 敌兵布阵
- Ubuntu下载android源码