poj 3104 二分答案
来源:互联网 发布:c语言添加线程 编辑:程序博客网 时间:2024/05/20 09:24
题意:
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 longusing 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;}
0 0
- poj 3104 二分答案
- POJ 3104 Drying-二分答案
- poj 3104 Drying 二分答案
- POJ 3104 Drying (二分答案)
- poj 3104 Drying (二分搜索答案)
- poj 3258二分答案
- POJ 3273 二分答案
- POJ 3122(二分答案)
- poj 3122 Pie 二分答案
- poj 3658 二分枚举答案。
- POJ 3122 Pie【二分答案】
- POJ 1759 Garland 二分答案
- POJ 3122 Pie 二分答案
- POJ-3273(二分答案)
- POJ 2112 floyd+二分答案+网络流
- poj 2112 二分答案+最大流
- poj 2723(2-sat+二分答案)
- poj 2112 最大流+floyd+二分答案
- PHP程序员的职业规划,走进PHP后端工程师的世界
- 技术团队建设
- Git常用命令(一)
- 机试算法讲解: 第4题 某一天是星期几?
- 快速排序详解
- poj 3104 二分答案
- xcode增加快捷键(不用插件)
- Android getActionBar() 为null解决方案
- Javascript_实现动态添加分类信息
- 知识空间诊断系统--ALEKS
- 链表中倒数第K个节点
- python爬取网页公告并批量存入至mysql中
- 快速求素数
- 学习JS(2)