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 ...
随机推荐
- form表单元素的值序列化成对象
/** * 将form表单元素的值序列化成对象 * param: form jquery form对象 */ var serializeObject = function(form) { var o ...
- 爬虫7:selenium
1. 一个简单的使用例子 from selenium import webdriver from selenium.webdriver.common.by import By from seleniu ...
- 49.RocketMQ 双主搭建(本文非EamonSec原创)
声明:本文非EamonSec原创,copy自网上下载的某个个文件 1.RocketMQ介绍 1.1. 简介 RocketMQ 是一款分布式.队列模型的消息中间件,具有以下特点: 能够保证严格的消息顺序 ...
- QuantLib 金融计算——随机过程之 Heston 过程
目录 QuantLib 金融计算--随机过程之 Heston 过程 Heston 过程 参考文献 如果未做特别说明,文中的程序都是 Python3 代码. QuantLib 金融计算--随机过程之 H ...
- PXE+Kickstart 批量安装CentOS 7
安装之前 将需要安装 CentOS 的服务器与 PXE 服务器通过网络设备连接:PXE 服务器安装 CentOS,并且关闭firewalld.selinux,设置静态IP地址,本例设为10.0.0.1 ...
- #Go# 常用类型转换
#string 2 int int, err := strconv.Atoi(string) #string 2 int64 int64, err := strconv.ParseInt(string ...
- 【App性能监控】:Android studio环境的搭建(以及遇到个各种坑)
今天搭建app性能测试环境,使用的是android studio的Android Device Monitor抓取trace日志分析: 1,下载最新的android studio安装,这一步没啥问题: ...
- SBC应用
在VoIP呼叫中主要使用会话发起协议(SIP),H.323和MGCP呼叫信令协议,Sbc 在主叫和被叫的信令/媒体路径之间引入. 通常,SBC隐藏网络拓扑,接管呼入并生成到新的请求分支到被叫.技术上叫 ...
- Handover
In brief, eNodeB select one MME based on IE: Relative MME Capacity in S1 Setup Response, S-GW and P- ...
- Cpython 支持的线程
因为Python解释器帮你自动定期进行内存回收,你可以理解为python解释器里有一个独立的线程,每过一段时间它起wake up做一次全局轮询看看哪些内存数据是可以被清空的,此时你自己的程序 里的线程 ...