Drying
Drying
http://poj.org/problem?id=3104
| Time Limit: 2000MS | Memory Limit: 65536K | |
| Total Submissions: 23212 | Accepted: 5842 |
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
设x1为自然晾干的时间,x2为被烘干的时间
a_i=x1+k*x2,mid=x1+x2,可得 x2=(a_i-mid)/(k-1),答案向上取整
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<vector>
#include<cmath>
#include<string.h>
#include<stdlib.h>
#include<stack>
#include<queue>
#include<cstdio>
#include<vector>
typedef long long ll;
const long long MOD=;
#define maxn 100005
using namespace std; ll n,k;
ll a[maxn]; bool Check(ll mid){
ll sum=;
ll tmp,tt;
for(int i=;i<=n;i++){
if(a[i]>mid){
sum+=ll(ceil((a[i]-mid)*1.0/(k-)));
}
}
if(sum<=mid) return true;
return false;
} int main(){
while(~scanf("%lld",&n)){
ll L=,R=,mid;
for(int i=;i<=n;i++){
scanf("%lld",&a[i]);
R=max(R,a[i]);
}
scanf("%lld",&k);
if(k==){
cout<<R<<endl;
continue;
} while(L<=R){
mid=L+R>>;
if(Check(mid)){
R=mid-;
}
else{
L=mid+;
}
}
printf("%lld\n",L);
}
}
Drying的更多相关文章
- POj3104 Drying(二分)
Drying Time Limit: 2000MS Memory Limit: 65536K Description It is very hard to wash and especially to ...
- POJ 3104 Drying(二分答案)
题目链接:http://poj.org/problem?id=3104 ...
- POJ3104 Drying(二分查找)
POJ3104 Drying 这个题由于题目数据比较大(1 ≤ ai ≤ 109),采用贪心的话肯定会超时,自然就会想到用二分. 设C(x)为true时表示所用时间为X时,可以把所有的衣服都烘干或者自 ...
- poj 3104 Drying(二分搜索之最大化最小值)
Description It is very hard to wash and especially to dry clothes in winter. But Jane is a very smar ...
- Drying(贪心)
Drying Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 11512 Accepted: 2977 Descripti ...
- Drying poj3104(二分)
Drying Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7916 Accepted: 2006 Descriptio ...
- Drying POJ - 3104
It is very hard to wash and especially to dry clothes in winter. But Jane is a very smart girl. She ...
- POJ3104 Drying 2017-05-09 23:33 41人阅读 评论(0) 收藏
Drying Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 15604 Accepted: 3976 Descripti ...
- poj 3104 Drying(二分查找)
题目链接:http://poj.org/problem?id=3104 Drying Time Limit: 2000MS Memory Limit: 65536K Total Submissio ...
随机推荐
- -Java-Runoob-高级教程-实例-数组:09. Java 实例 – 数组扩容
ylbtech-Java-Runoob-高级教程-实例-数组:09. Java 实例 – 数组扩容 1.返回顶部 1. Java 实例 - 数组扩容 Java 实例 以下实例演示了如何在数组初始化后 ...
- Nginx Tengine ngx_http_upstream_check_module 健康功能检测使用
该模块可以为Tengine提供主动式后端服务器健康检查的功能. 该模块在Tengine-1.4.0版本以前没有默认开启,它可以在配置编译选项的时候开启:./configure --with-http_ ...
- 亚马逊云EC2做PPTP SERVER的笔记
1.在亚马逊控制台上启动实例 2. 3. 4. 5. 6.配置安全组,把你的IP开放所有流量. 7. 用你自己的亚马逊KEY或者生成一个新的KEY来登录EC2 8.开始搭建VPN-PPTP——how ...
- [UE4]头文件循环依赖C++
有2个类:aaa和bbb. aaa.h已经#include了bbb.h,则bbb.h就不能#include aaa.h,但bbb.cpp可以#include aaa.h bbb.h已经#include ...
- Maven 配置tomcat插件
使用tomcat插件来访问maven 1 先下载tomcat插件(在pom中配置) <!-- 配置Tomcat插件 --> <plugin> <groupId>or ...
- jps命令发生异常
当在集群里输入jps命令时报如下错误: 我就开始检查jdk,感觉应该是centos自动的jdk没卸载干净跟后面安装的jdk冲突 先通过命令 rpm -qa|grep java 查看jdk信息 把这几个 ...
- solr之~模糊查询
有的时候,我们一开始不可能准确地知道搜索的关键字在 Solr 中查询出的结果是什么,因此,Solr 还提供了几种类型的模糊查询.模糊匹配会在索引中对关键字进行非精确匹配.例如,有的人可能想要搜索某个前 ...
- 听听八年阿里架构师怎样讲述Dubbo和Spring Cloud微服务架构
转自:https://baijiahao.baidu.com/s?id=1600174787011483381&wfr=spider&for=pc 微服务架构是互联网很热门的话题,是互 ...
- ORM Nhibernate框架在项目中的配置
在项目中使用 Nhibernet 时,一定要将 配置文件 .xml 编译方式设置为 嵌入式资源,否则在运行项目时就会出现错误. 以下是hibernate.cfg.xml 的配置,在配置中使用的是 M ...
- VC如何得到一个文件夹的路径
VC中没有现成的函数来选择一个文件夹,但这是经常会用到的,怎么办?自动动手,丰衣足食! 使用SHBrowseForFolder,代码如下: #include int SelFolder(HWND ...