poj 3104 二分答案
2015-07-30 23:28
267 查看
题意:
n件湿度为num的衣服,每秒钟自己可以蒸发掉1个湿度。
然而如果使用了暖炉,每秒可以烧掉k个湿度,但不计算蒸发了。
现在问这么多的衣服,怎么烧事件最短。
解析:
二分答案咯。
代码:
n件湿度为num的衣服,每秒钟自己可以蒸发掉1个湿度。
然而如果使用了暖炉,每秒可以烧掉k个湿度,但不计算蒸发了。
现在问这么多的衣服,怎么烧事件最短。
解析:
二分答案咯。
代码:
#include <iostream> #include <cstdio> #include <cstdlib> #include <algorithm> #include <cstring> #include <cmath> #include <stack> #include <vector> #include <queue> #include <map> #include <climits> #include <cassert> #define LL long long using namespace std; const int inf = 0x3f3f3f3f; const double eps = 1e-8; const double pi = acos(-1.0); const double ee = exp(1.0); const int maxn = 100000 + 10; LL num[maxn]; LL k; int n; bool ok(LL x) { LL cnt = 0; for (int i = 0; i < n; i++) { if (x < num[i]) { LL t = ceil((num[i] - x) * 1.0 / (k - 1)); cnt += t; } } return cnt <= x; } int main() { #ifdef LOCAL freopen("in.txt", "r", stdin); #endif // LOCAL while (~scanf("%d", &n)) { LL maxV = 0; for (int i = 0; i < n; i++) { scanf("%lld", &num[i]); maxV = maxV < num[i] ? num[i] : maxV; } scanf("%lld", &k); if (k == 1) { printf("%lld\n", maxV); continue; } LL lo = 1, hi = maxV; LL ans; while (lo <= hi) { LL mi = (lo + hi) >> 1; if (ok(mi)) { hi = mi - 1; ans = mi; } else lo = mi + 1; } printf("%lld\n", ans); } return 0; }
相关文章推荐
- poj 1364 King(差分约束)(中等)
- 数据库MySQL基础——增删查改
- V3.1管理经验总结分析
- 机试算法讲解: 第4题 某一天是星期几?
- Visual Studio 出现“无法解析的外部符号”错误
- QT在CT上的安装及运行
- 快速排序详解
- JDBC接口讲解与底层实现分析(上)
- 技术团队建设
- ABP领域层——领域事件(Domain events)
- redis配置文件redis.conf中文版
- [转]iOS 中几种定时器 - 控制了时间,就控制了一切
- PHP程序员的职业规划,走进PHP后端工程师的世界
- iOS开发系列--UITableView全面解析
- C++对象模型——Copy Constructor 的建构操作(第二章)
- Git常用命令(一)
- Ubuntu Server PHP常用扩展库的安装
- import sys sys.path.append(...)
- Android Fragment数据保存问题
- js注入