POJ 3104
| Time Limit: 2000MS | Memory Limit: 65536K | |
| Total Submissions: 7959 | Accepted: 2014 |
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
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <queue> using namespace std; #define maxn 100005 typedef long long ll; int n,k;
int a[maxn]; bool judge(ll x) { ll sum = ;
for(int i = ; i <= n; ++i) {
if(a[i] - x <= ) continue;
if(k == ) {
if(sum < a[i]) sum = a[i];
} else {
sum += (a[i] - x) / (k - ) + ((a[i] - x) % (k - ) > );
}
} return sum <= x;
} void solve() {
ll l = ,r = ; for(int i = ; i <= n; ++i) {
r += a[i];
} while(l < r) {
ll mid = (l + r) >> ; if(judge(mid)) {
r = mid;
} else {
l = mid + ;
}
} cout << l << endl;
} int main() { // freopen("sw.in","r",stdin); scanf("%d",&n);
for(int i = ; i <= n; ++i) {
scanf("%d",&a[i]);
}
scanf("%d",&k); sort(a + ,a + n + ); solve(); return ;
}
POJ 3104的更多相关文章
- 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(二分答案)
[题目链接] 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 [二分 有坑点 好题]
传送门 表示又是神题一道 Drying Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9327 Accepted: 23 ...
- Divide and conquer:Drying(POJ 3104)
烘干衣服 题目大意:主人公有一个烘干机,但是一次只能烘干一件衣服,每分钟失水k个单位的水量,自然烘干每分钟失水1个单位的水量(在烘干机不算自然烘干的那一个单位的水量),问你最少需要多长时间烘干衣服? ...
- 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 Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 12568 Accepted: 3243 Descripti ...
- Drying POJ - 3104
It is very hard to wash and especially to dry clothes in winter. But Jane is a very smart girl. She ...
随机推荐
- .Net三维控件
AnyCAD .Net三维建模和可视化控件为.Net 4.0开发者提供简单易用的三维建模.三维可视化和文件交换的API. 30天试用版下载: 1. 三维建模 三维建模有以下功能: 三维基本体,如点. ...
- search help 概述
所谓search help 就是在前台调出一个query 得到一个value list 让用户选择需要的值 我们要做的就是给某些表/视图 设计一个可供查询的query 然后把这个query绑定到需要的 ...
- solr6安装部署
难得写篇自己的原创文档了,哈哈哈,原谅我知识浅薄,积淀太少 一.涉及到的软件和环境jdk1.8.0_92,tomcat8,zookeeper3.4.8,solr6.1.0(solr6需要jdk8以上环 ...
- 例题6-7 Trees on the level ,Uva122
本题考查点有以下几个: 对数据输入的熟练掌握 二叉树的建立 二叉树的宽度优先遍历 首先,特别提一下第一点,整个题目有相当一部分耗时在了第一个考查点上(虽然有些不必要,因为本应该有更简单的方法).这道题 ...
- JDK 动态代理实现原理
一.引言 Java动态代理机制的出现,使得Java开发人员不用手工编写代理类,只要简单地指定一组接口及委托类对象便能动态生成代理类.代理类会负责将所有方法的调用分派到委托对象上反射执行,在分派执行的过 ...
- Oracle bbed使用说明2---常用命令
一.BBED常用命令说明 先看帮助的说明 BBED> help all SET DBA [ dba | file#, block# ] SET FILENAME 'filename' SET F ...
- WPF学习05:2D绘图 使用Transform进行控件变形
在WPF学习04:2D绘图 使用Shape绘基本图形中,我们了解了如何绘制基本的图形. 这一次,我们进一步,研究如何将图形变形. 例子 一个三角形,经Transform形成组合图形: XAML代码: ...
- 【Go】为什么用go; Golang Erlang 前世今生
给自己一条退路,再次比较Erlang和Golang 2014-6-28 陈叶皓 chenyehao@gmail.com 雨天的周末,适合码字的时节... 一年前我开始学习go语言的时候,如获至宝,既有 ...
- thinkphp通行证服务,验证登录,注销登录
<?php /** * 通行证服务 */ class PassportService extends Service { /** * 验证用户或者管理员是否已登录 * @return boole ...
- JVM内幕:Java虚拟机详解
这篇文章解释了Java 虚拟机(JVM)的内部架构.下图显示了遵守 Java SE 7 规范的典型的 JVM 核心内部组件. 上图显示的组件分两个章节解释.第一章讨论针对每个线程创建的组件,第二章节讨 ...