Drying POJ - 3104
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 aiseparated 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 这题水题二分(不过要注意的点非常多,非常容易WA)
(a[i]-x+k-2)/(k-1)这个是一个向上取整
二分答案,将时间进行二分
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
using namespace std;
long long a[],n,k;
int check(long long x)
{
long long time=;
if (k==) return ;
for (int i= ;i<n ;i++ ){
if (a[i]>x) time+=(a[i]-x+k-)/(k-);
}
if (time>x) return ;
return ;
}
int main() {
long long maxn;
while(scanf("%lld",&n)!=EOF){
maxn=;
for (int i= ;i<n ;i++ ){
scanf("%lld",&a[i]);
maxn=max(maxn,a[i]);
}
scanf("%lld",&k);
long long l=,r=maxn,mid;
while(r-l>){
mid=(l+r)/;
if (check(mid)) l=mid;
else r=mid;
}
printf("%lld\n",r);
}
return ;
}
Drying POJ - 3104的更多相关文章
- Divide and conquer:Drying(POJ 3104)
烘干衣服 题目大意:主人公有一个烘干机,但是一次只能烘干一件衣服,每分钟失水k个单位的水量,自然烘干每分钟失水1个单位的水量(在烘干机不算自然烘干的那一个单位的水量),问你最少需要多长时间烘干衣服? ...
- Drying POJ - 3104 二分 最优
题意:有N件湿的衣服,一台烘干机.每件衣服有一个湿度值.每秒会减一,如果用烘干机,每秒会减k.问最少多久可以晒完. 题解:二分.首先时间越长越容易晒完. 其次判定函数可以这样给出:对于答案 X,每一个 ...
- POJ 3104 Drying(二分答案)
题目链接:http://poj.org/problem?id=3104 ...
- poj 3104 Drying(二分查找)
题目链接:http://poj.org/problem?id=3104 Drying Time Limit: 2000MS Memory Limit: 65536K Total Submissio ...
- 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 [二分 有坑点 好题]
传送门 表示又是神题一道 Drying Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9327 Accepted: 23 ...
- 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(二分
Drying Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 22163 Accepted: 5611 Descripti ...
随机推荐
- 洛谷 [P1280] 尼克的任务
DP 题目问的是最大空暇时间,那么就定义dp[i]为第i分钟的最大空暇时间,显然满足最优子结构,我们发现dp[i]仅与其后的值有关,那么从后往前推,如果第i分钟没有任务,dp[i]=dp[i+1],如 ...
- Codeforces 250 E. The Child and Binary Tree [多项式开根 生成函数]
CF Round250 E. The Child and Binary Tree 题意:n种权值集合C, 求点权值和为1...m的二叉树的个数, 形态不同的二叉树不同. 也就是说:不带标号,孩子有序 ...
- FlappyBird Pygame
视频链接 GitHub链接:https://github.com/yanpeng1314/FlappyBird from InitObject import * def startGame(): mo ...
- LeetCode - 776. Split BST
Given a Binary Search Tree (BST) with root node root, and a target value V, split the tree into two ...
- 深入分析Java ClassLoader的原理(转)
一.什么是ClassLoader? 大家都知道,当我们写好一个Java程序之后,不是管是CS还是BS应用,都是由若干个.class文件组织而成的一个完整的Java应用程序,当程序在运行时,即会调用该程 ...
- 使用EL表达式调用java方法
首先,新建一个类,类中写一个静态方法 public class PrivilegeUtils { public static Boolean checkPrivilegeByName(User use ...
- 卷积神经网络(CNN)在句子建模上的应用
之前的博文已经介绍了CNN的基本原理,本文将大概总结一下最近CNN在NLP中的句子建模(或者句子表示)方面的应用情况,主要阅读了以下的文献: Kim Y. Convolutional neural n ...
- Git 上传 GitHub
1.下载 2.安装 3.功能识别 3-1.查看git版本 git --version 3-2.移除原来的版本 yum remove git 4.配置 4-1.用户配置信息 git config ...
- 【ASP.NET Core】解决“The required antiforgery cookie "xxx" is not present”的错误
当你在页面上用 form post 内容时,可能会遇到以下异常: The required antiforgery cookie "????????" is not present ...
- OKL4虚拟化技术跟踪
这篇博客准备介绍OKL4的研究进展,本文的内容主要根据我个人阅读<OKL4_LongPaper_2010_HW_VM>这篇文章之后的理解,我也根据这篇论文的内容做了一些实验,奈何此论文涉及 ...