Drying poj3104(二分)
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 7916 | Accepted: 2006 |
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
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
int a[],n,k,max;
bool check(int x)
{
int i;
long long sum=;
for(i=;i<n;i++)
{
if(a[i]>x)
{
sum+=(a[i]-x)/(k-);
if((a[i]-x)%(k-)) sum++;
}
}
if(sum>x)return ;
else return ;
}
int fun()
{
int l=,r=max;
while(l<=r)
{
int m=(l+r)>>;
if(check(m))
r=m-;
else l=m+;
}
return l;
}
int main()
{
int i;
scanf("%d",&n);
for(i=;i<n;i++)scanf("%d",&a[i]),max=max>a[i]?max:a[i];
scanf("%d",&k);
if(k==)
printf("%d\n",max);
else
printf("%d\n",fun());
}
Drying poj3104(二分)的更多相关文章
- Drying [POJ3104] [二分答案]
背景 每件衣服都有一定单位水分,在不适用烘干器的情况下,每件衣服每分钟自然流失1个单位水分,但如果使用了烘干机则每分钟流失K个单位水分,但是遗憾是只有1台烘干机,每台烘干机同时只能烘干1件衣服,请问要 ...
- 【POJ - 3104 】Drying(二分)
Drying 直接上中文 Descriptions 每件衣服都有一定单位水分,在不使用烘干器的情况下,每件衣服每分钟自然流失1个单位水分,但如果使用了烘干机则每分钟流失K个单位水分,但是遗憾是只有1台 ...
- poj3104 Drying(二分最大化最小值 好题)
https://vjudge.net/problem/POJ-3104 一开始思路不对,一直在想怎么贪心,或者套优先队列.. 其实是用二分法.感觉二分法求最值很常用啊,稍微有点思路的二分就是先推出公式 ...
- POJ 3104 Drying(二分
Drying Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 22163 Accepted: 5611 Descripti ...
- POJ 3104:Drying(二分)
题目大意:你有一台机器可以烘干衣物,现在有n个衣物需要烘干,每件衣服都有一个值表示含水量,烘干机一秒可以烘干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 ...
- POJ3104 Drying(二分查找)
POJ3104 Drying 这个题由于题目数据比较大(1 ≤ ai ≤ 109),采用贪心的话肯定会超时,自然就会想到用二分. 设C(x)为true时表示所用时间为X时,可以把所有的衣服都烘干或者自 ...
- POj3104 Drying(二分)
Drying Time Limit: 2000MS Memory Limit: 65536K Description It is very hard to wash and especially to ...
随机推荐
- leetcode 001 Two Sun
Given an array of integers, return indices of the two numbers such that they add up to a specific ta ...
- Git 入门篇
什么是Git Git是Linux发明者Linus开发的一款新时代的版本控制系统. Git安装 Mac:https://sourceforge.net/projects/git-osx-instal ...
- NHibernate教程(11)--多对多关联查询
本节内容 多对多关系引入 多对多映射关系 多对多关联查询 1.原生SQL关联查询 2.HQL关联查询 3.Criteria API关联查询 结语 多对多关系引入 让我们再次回顾在第二篇中建立的数据模型 ...
- 标题:a++和++a的区别
以前我也是老搞不懂a++和++a的区别, 后来看了很多资料, 终于总结出来一条规律, 小白专用! 看完这个例子就懂了: 例1:$a = 8, 求 ++a + a++ - --a + a-- + ++a ...
- JSP小记
0.配置servlet的模板 1.找Jar文件:\Common\plugins (myeclipse.ini文件中查看) * com.genuitec.eclipse.wizards*.jar 2.找 ...
- bootstrap 表单+按钮+对话框
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...
- oop作业二—circle
oop作业-circle 题目描述 编写一个程序,要求根据给定的圆的半径求圆的面积,并将求得的结果打印出来. 要求: 输入输出采用cin和cout. 建立一个工程,将程序写成两个.cpp和一个.h的形 ...
- 关于C语言
对于C语言方面 觉得自己在数组方面比较薄弱,寒假之前也借了一些书关于C语言的希望能在家里好好看看,也看了差不多两三百页,视频没怎么看,看了七八集,希望学一些深入的语法或者说是算法.
- 【集美大学1411_助教博客】团队作业7——Alpha冲刺之事后诸葛亮
写在前面的话 alpha阶段都顺利完成了,大家这次作业完成得都很认真.我觉得通过这些问题,大家既可以回顾自己的alpha阶段,又可以给beta阶段做一些指引.但看了所有组的博客,没有一个组在这些问题之 ...
- 201521123122 《java程序设计》 第四周学习总结
1. 本周学习总结 1.1 尝试使用思维导图总结有关继承的知识点. 1.2 使用常规方法总结其他上课内容. 这个思维导图比较简单,详细内容点击此处 2. 书面作业 注释的应用 使用类的注释与方法的注释 ...