poj 3104 dring 二分
| Time Limit: 2000MS | Memory Limit: 65536K | |
| Total Submissions: 7684 | Accepted: 1967 |
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
/* 题意:烤衣服,每分钟水量少k。自然干,每分钟少1.
给10^5件衣服的水量。
求最小的时间,全部的衣服都干了。
不能理解成,烤衣服的时候,也自然干。k已经包括了。 二分时间。对于时间mid判断能否实现。 */ #include<iostream>
#include<stdio.h>
#include<cstring>
#include<cstdlib>
#include<algorithm>
using namespace std; typedef __int64 LL;
LL a[]; bool fun(LL x,LL n,LL m)
{
LL i,num=,cur;
if( m== )
{
for(num=-,i=;i<=n;i++)
if(a[i]>num) num=a[i];
}
else
{
for(i=,num=;i<=n;i++)
{
cur=a[i]-x;
if( cur<=) continue;
if(cur%(m-)==)
num=num+cur/(m-);
else num=num+cur/(m-)+;
}
}
if( num<=x)return true;
else return false;
}
int main()
{
LL n,i,l,r,mid,m;
bool cur;
while(scanf("%I64d",&n)>)
{
for(i=;i<=n;i++)
scanf("%I64d",&a[i]);
scanf("%I64d",&m);
for(i=,l=,r=;i<=n;i++)
{
if(a[i]%m==)
r=r+a[i]/m;
else r=r+a[i]/m+;
}
while(l<r)
{
mid=(l+r)/;
cur=fun(mid,n,m);
if( cur==true)
r=mid;
else l=mid+;
}
printf("%I64d\n",r);
}
return ;
}
poj 3104 dring 二分的更多相关文章
- 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 [二分 有坑点 好题]
传送门 表示又是神题一道 Drying Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9327 Accepted: 23 ...
- POJ 3104 Drying (二分+精度)
题目链接:click here~~ [题目大意]: 题意:有一些衣服,每件衣服有一定水量,有一个烘干机,每次能够烘一件衣服,每分钟能够烘掉k单位水. 每件衣服没分钟能够自己主动蒸发掉一单位水, 用烘干 ...
- poj 2318 叉积+二分
TOYS Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 13262 Accepted: 6412 Description ...
- poj 2049(二分+spfa判负环)
poj 2049(二分+spfa判负环) 给你一堆字符串,若字符串x的后两个字符和y的前两个字符相连,那么x可向y连边.问字符串环的平均最小值是多少.1 ≤ n ≤ 100000,有多组数据. 首先根 ...
- 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 Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 12568 Accepted: 3243 Descripti ...
随机推荐
- 搭建一个ES6开发环境
一.首先先建立一个项目工程目录,并在目录下建立两个文件夹:src和dist src:书写ES6代码的文件夹,写的js程序都放在这里. dist:利用Babel编译成的ES5代码的文件夹,在HTML页面 ...
- 关于类的成员,public,private修饰符
类的成员要:属性,方法 属性:是它本身所居有的东西,比如人的特征,也可以这样理解属性是静态状态 方法:是这些属性通过方法行为发生改变,也就是方法是动态,可以对属性进行更新 public 公共的,可以被 ...
- (Lua) C++ 加入 Lua 環境擴充應用強度
Lua 在網上有非常多的介紹,就是一個小而巧的語言,可以放入嵌入式系統 也可以在一般的應用上非常強大,這邊主要記錄如何讓Lua加入C++裡頭應用 Lua source code 是以 C 語言下去編寫 ...
- IntelliJ IDEA 18 周岁,吐血推进珍藏已久的必装插件
IntelliJ IDEA是目前最好最强最智能的Java IDE,前几天,他刚刚年满18岁.  本文,给大家推荐几款我私藏已久的,自己经常使用的,可以提升代码效率的插件. IDEA插件简介 常见的I ...
- SVN版本库备份和恢复
1.版本库备份 1.1.svnadmin dump方式备份 此方法借助的是Subversion官网推荐的svnadmin dump备份方式,它的优点是比较灵活,既可以进行全量备份又可以进行增量备份,并 ...
- 网络基础 05_DHCP
1 DHCP概述 DHCP (Dynamic Host Configuration Protocol)是一种动态的向Internet终端提供配置参数的协议.在终端提出申请之后,DHCP可以向终端提供I ...
- python学习,day4:装饰器的使用示例2
这个例子比较复杂 # coding=utf-8 # Author: RyAn Bi user,passwd = ' #输入用户名密码 def auth(auth_type): #装饰器第一层,确定鉴权 ...
- abp 依赖注入声明
public class SchedulerManager : ISingletonDependency { private ILogger logger; public SchedulerManag ...
- Dijkstra+优先队列 堆优化
关于堆优化 传统\(Dijkstra\),在选取中转站时,是遍历取当前最小距离节点,但是我们其实可以利用小根堆(STL的priority_queue)优化这个过程,从而大大降低复杂(\(O(V2+E) ...
- [DPF] DB2 DPF 搭建实战
1. Server 准备 2. NFS 系统设置 3. 创建实例 4. rsh/ssh 5. 测试 Server: 192.168.122.1 dpf01.dpf.com dpf01 192.16 ...