POJ3104_DRYING_二分
来源:互联网 发布:mac spark 环境搭建 编辑:程序博客网 时间:2024/06/04 18:41
题目描述
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 #132 3 95sample input #232 3 65
Sample Output
sample output #13sample output #22
解题报告
电吹风吹衣服问题。
我们二分最短可以吹干所有衣物的时间。自然干的不需要吹,来不及干的吹干。。。
很简单
代码
#include <iostream>#include <stdio.h>#include <cstring>long long a[100555],n,k;using namespace std;bool jud(long t){ long long res=t; for(long i=1;i<=n;i++) if(a[i]>t) res-=((a[i]-t)%(k-1)>0?((a[i]-t)/(k-1))+1:(a[i]-t)/(k-1)); return res>=0?true:false;}long solve(){ if(k<=1) { long long maximum=-1; for(long i=1;i<=n;i++) if(a[i]>maximum) maximum=a[i]; return maximum; } long long mid,l=1,r=2e9 ; while(l<r){ mid=(l+r)>>1; if(jud(mid)) r=mid; else l=mid; if(r-l==1) if(jud(l)) return l; else return r; } return mid;}int main(){ while(scanf("%d",&n)!=EOF){ for(long i=1;i<=n;i++) scanf("%d",&a[i]); scanf("%d",&k); long long res=solve(); printf("%d\n",res); } return 0;}
- POJ3104_DRYING_二分
- POJ3104_Drying_二分
- 二分
- 二分
- 二分
- 二分
- 二分
- 二分。
- 二分
- 二分
- 二分
- 二分
- 二分
- 二分
- 二分
- 二分
- 二分~~
- 二分
- 【风宇冲】Unity3D教程宝典之插件篇:Unity3D插件详细评测及教学下载
- leetcode 难题 Unique Binary Search Trees
- Where is the Marble
- 单片机复习程序例举005 -- DS1302时钟芯片
- drupal7自定义输出节点内容($content里的每一个字段)
- POJ3104_DRYING_二分
- Android记事本开发之SQLite数据库实现
- CC2530与zigbee学习笔记の初识zigbee(3)
- python进阶七_文件操作(一)
- 005_013 Python 寻找子序列 字符串应该用find 否则用KMP
- [连载]C#程序设计(14)--- 泛型和容器
- 编程之美热身赛 题目1 : 传话游戏
- POJ2479 Java 动态规划
- POJ3104_Pie_二分