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 ...
随机推荐
- java异常术语
.检查性异常: 不处理编译不能通过 .非检查性异常:不处理编译可以通过,如果有抛出直接抛到控制台(所有RuntimeException的派生类都是非检查型异常) .非运行时异常: 就是检查性异常4.运 ...
- 2017.06.04【NOIP提高组】模拟赛B组:
t1 jzoj3762 过河 路径分段,计算出向上移对答案贡献最大的一段路,再使用堆来维护即可 代码: #include<bits/stdc++.h> using namespace st ...
- 给 console 添加颜色
简评:使用 %c 声明可以给 console 的输出添加 CSS 样式,日志太多的话,给不同种类的日志设置不同的样式,可以极大的提升阅读体验. 什么是 %c %c: 标识将 CSS 样式应用于 %c ...
- 学习前端页面css定位
css元素框定位 一.相对定位: 相对定位是一个非常容易掌握的概念.如果对一个元素进行相对定位,它将出现在它所在的位置上.然后,可以通过设置垂直或水平位置,让这个元素“相对于”它的起点进行移动.pos ...
- 安卓monkey自动化测试,软硬回车
1.Monkey程序介绍 在android手机上做自动化测试,monkey比cts,Android UnitTest 好用多了,他其实是继承与adb shell中的一段的shell指令. monkey ...
- pygame学习_part1_pygame写程序前的准备工作
import pygame from pygame import * pygame.init() #准备pygame,不准备无法使用功能 pygame.display.set_mode((x,y坐标) ...
- 【Alpha】Phylab 测试报告
PhyLab Alpha 测试报告 测试中发现的bug Bug 可能原因 实验区域发布评论,如果需要验证码,无法填写 评论频率过快,实验区未接入验证码系统 忘记密码,但无邮件发送 忘记密码部分暂未修复 ...
- Python flask Reason: image not found libmysqlclient.21.dylib
Python flask Reason: image not found libmysqlclient.21.dylib 折腾了半个下午,在这里找到了答案,在此记录一下,以免后人躺坑 错误提示: Im ...
- win10 下springcloud打包docker镜像部署。
1:建一个最简单的springcloud应用. 2:在根目录下新建dockerfile,文件如下: FROM openjdk:8-jdk-alpine VOLUME /tmp ARG JAR_FILE ...
- C语言warning的收集和总结
1. warning: suggest parentheses around comparison in operand of '&' 分析: &运算符的优先级较低,低于==和!=运算 ...