POJ 3104
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 7959 | Accepted: 2014 |
Description
It is very hard to wash and especially to dry clothes in winter. But Jane is a very smart girl. She is not afraid of this boring process. Jane has decided to use a radiator to make drying faster. But the radiator is small, so it can hold only one thing at a time.
Jane wants to perform drying in the minimal possible time. She asked you to write a program that will calculate the minimal time for a given set of clothes.
There are n clothes Jane has just washed. Each of them took ai water during washing. Every minute the amount of water contained in each thing decreases by one (of course, only if the thing is not completely dry yet). When amount of water contained becomes zero the cloth becomes dry and is ready to be packed.
Every minute Jane can select one thing to dry on the radiator. The radiator is very hot, so the amount of water in this thing decreases by k this minute (but not less than zero — if the thing contains less than k water, the resulting amount of water will be zero).
The task is to minimize the total time of drying by means of using the radiator effectively. The drying process ends when all the clothes are dry.
Input
The first line contains a single integer n (1 ≤ n ≤ 100 000). The second line contains ai separated by spaces (1 ≤ ai ≤ 109). The third line contains k (1 ≤ k ≤ 109).
Output
Output a single integer — the minimal possible number of minutes required to dry all clothes.
Sample Input
sample input #1
3
2 3 9
5 sample input #2
3
2 3 6
5
Sample Output
sample output #1
3 sample output #2
2
Source
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <queue> using namespace std; #define maxn 100005 typedef long long ll; int n,k;
int a[maxn]; bool judge(ll x) { ll sum = ;
for(int i = ; i <= n; ++i) {
if(a[i] - x <= ) continue;
if(k == ) {
if(sum < a[i]) sum = a[i];
} else {
sum += (a[i] - x) / (k - ) + ((a[i] - x) % (k - ) > );
}
} return sum <= x;
} void solve() {
ll l = ,r = ; for(int i = ; i <= n; ++i) {
r += a[i];
} while(l < r) {
ll mid = (l + r) >> ; if(judge(mid)) {
r = mid;
} else {
l = mid + ;
}
} cout << l << endl;
} int main() { // freopen("sw.in","r",stdin); scanf("%d",&n);
for(int i = ; i <= n; ++i) {
scanf("%d",&a[i]);
}
scanf("%d",&k); sort(a + ,a + n + ); solve(); return ;
}
POJ 3104的更多相关文章
- POJ 3104 Drying(二分答案)
题目链接:http://poj.org/problem?id=3104 ...
- POJ 3104 Drying 二分
http://poj.org/problem?id=3104 题目大意: 有n件衣服,每件有ai的水,自然风干每分钟少1,而烘干每分钟少k.求所有弄干的最短时间. 思路: 注意烘干时候没有自然风干. ...
- POJ 3104 Drying(二分答案)
[题目链接] http://poj.org/problem?id=3104 [题目大意] 给出n件需要干燥的衣服,烘干机能够每秒干燥k水分, 不在烘干的衣服本身每秒能干燥1水分 求出最少需要干燥的时间 ...
- poj 3104 Drying(二分查找)
题目链接:http://poj.org/problem?id=3104 Drying Time Limit: 2000MS Memory Limit: 65536K Total Submissio ...
- POJ 3104 Drying [二分 有坑点 好题]
传送门 表示又是神题一道 Drying Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9327 Accepted: 23 ...
- Divide and conquer:Drying(POJ 3104)
烘干衣服 题目大意:主人公有一个烘干机,但是一次只能烘干一件衣服,每分钟失水k个单位的水量,自然烘干每分钟失水1个单位的水量(在烘干机不算自然烘干的那一个单位的水量),问你最少需要多长时间烘干衣服? ...
- poj 3104 Drying(二分搜索之最大化最小值)
Description It is very hard to wash and especially to dry clothes in winter. But Jane is a very smar ...
- poj 3104 二分
Drying Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 12568 Accepted: 3243 Descripti ...
- Drying POJ - 3104
It is very hard to wash and especially to dry clothes in winter. But Jane is a very smart girl. She ...
随机推荐
- 如何判断一个js对象是不是Array
1. instance of 2.constructor 3. isArray 1.var a=new Array(); a instanceof Array; //true 2.var a=new ...
- 一致性哈希(consistent hashing)算法
文章同步发表在博主的网站朗度云,传输门:http://www.wolfbe.com/detail/201608/341.html 1.背景 我们都知道memcached服务器是不提供分布 ...
- 双机倒换(NewStartHA,SKYbility,hacmp,hp unix双机)
1.Suse linux (NewStartHA): # cli cli:~>service-migrate Select service to migrate: ...
- Linux学习笔记之VI(VIM)编辑器
百度关于vi的资料 http://baike.baidu.com/view/908054.htm 关于vi 和vim的介绍可以在上面的网址看到. 1 进入和退出vi 进入:在终端命令行输入 vi ...
- html设置360兼容/极速模式
由于众所周知的情况,国内的主流浏览器都是双核浏览器:基于Webkit内核用于常用网站的高速浏览.基于IE的内核用于兼容网银.旧版网站.以360的几款浏览器为例,我们优先通过Webkit内核渲染主流的网 ...
- 测试驱动开发实践 - Test-Driven Development
一.前言 不知道大家有没听过“测试先行的开发”这一说法,作为一种开发实践,在过去进行开发时,一般是先开发用户界面或者是类,然后再在此基础上编写测试. 但在TDD中,首先是进行测试用例的编写,然后再进行 ...
- Png图片的透明部分穿透测试
private void Window_MouseMove(object sender, MouseEventArgs e){ NavBtnList.Clear(); Point mou ...
- JNI-入门之一
下面我们开始编写HelloWorld程序,由于涉及到要编写c/c++代码因此我们会在开发中使用Microsoft VC++工具. 编写java代码我们在硬盘上建立一个hello目录作为我们的工作目录, ...
- Ubuntu中NetBeans C/C++配置、编译
系统环境:Ubuntu 9.04软件环境:NetBeans 6.7.1 C/C++ .JDK1.6.0_16本次目的:完成NetBeans 6.7.1 C/C++ 的配置工作.编译测试及对中文支持 首 ...
- LoadRunner 学习笔记(2)VuGen运行时设置Run-Time Setting
定义:在Vugen中Run-Time Setting是用来设置脚本运行时所需要的相关选项