uva 1648 Business Center 简单数学
来源:互联网 发布:windows激活密匙在哪 编辑:程序博客网 时间:2024/06/09 21:51
题意:一座无限高的大楼,m座电梯,给出每个电梯一次上升和下降得层数u、d,求n次以后最少上升多少层。
挺简单的题,暂且算是数学吧,刘汝佳也是放到了紫书第十章。
用x表示上升次数,y表示下降次数,上升层数就是x*u - y * d,因为x + y = n,所以x * (u + d) - n * d,二分x找大于0的最小值就可以了。
#include <iostream>#include <cstdio>#include <cstring>using namespace std;int deal(int n, int u, int d) { int b = 0, e = n; int x = 0x3f3f3f3f; while(b <= e) { int m = (b + e) >> 1; if(m * (u + d) - n * d > 0) { x = m * (u + d) - n * d; e = m - 1; } else b = m + 1; } return x;}int main() { int n, m, u, d, i; while(~scanf("%d%d", &n, &m)) { int ans = 0x3f3f3f3f; while(m--) { scanf("%d%d", &u, &d); int t = deal(n, u, d); if(t < ans) ans = t; } printf("%d\n", ans); } return 0;}
0 0
- uva 1648 Business Center 简单数学
- uva 1648 Business Center 数学+二分
- UVA 1648(p346)----Business Center
- Business Center
- Business Center
- Business Intelligence Center
- poj3863 Business Center 贪心
- 4159: [Neerc2009]Business Center
- poj 3863Business Center
- poj 3863 Business Center
- B. Business Center
- [POJ3863]Business Center
- UVa 11461 Square Numbers (简单数学)
- uva - 11636 - Hello World!(简单数学)
- uva 11388 GCD LCM(简单数学)
- uva 11889 Benefit(简单数学)
- UVA 11401-Triangle Counting-简单数学计算
- UVA 10002 Center of Masses
- C#开发第一天-选择一种开发语言
- 编程是工具,计算机也是工具
- 记录导入项目操作
- 基于Spring MVC(REST API)做单元测试(mockito)
- html2image 乱码
- uva 1648 Business Center 简单数学
- 系统端口详解
- iOS显示启动页时隐藏状态栏
- Objective-C 文件处理
- js序列化ajax参数对象
- 序列图
- Ubuntu14.04安装与安装后的软件的安装
- binder 分析(2)_client端程序
- 简述Android单位dp、sp、dip、px、等的区别和使用