Drying

来源:互联网 发布:德国pjur怎么样 知乎 编辑:程序博客网 时间:2024/06/03 23:39

Drying

Time Limit : 4000/2000ms (Java/Other)   Memory Limit : 131072/65536K (Java/Other)
Total Submission(s) : 93   Accepted Submission(s) : 30
Problem 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
<span lang="en-us"><p>The first line contains a single integer <i>n</i> (1 ≤ <i>n</i> ≤ 100 000). The second line contains <i>a<sub>i</sub></i> separated by spaces (1 ≤ <i>a<sub>i</sub></i> ≤ 10<sup>9</sup>). The third line contains <i>k</i> (1 ≤ <i>k</i> ≤ 10<sup>9</sup>).</p></span>
 

Output
<p>Output a single integer — the minimal possible number of minutes required to dry all clothes.</p>
 

Sample Input
<b>sample input #1</b>32 3 95<b>sample input #2</b>32 3 65
 

Sample Output
<b>sample output #1</b>3<b>sample output #2</b>2
题意:有n件衣服 每一件晒有一个湿度,干需要一定时间,给出每分钟可以烘干的湿度,
如果不烘干,则每分钟靠蒸发湿度-1,烘干的时候不蒸发 问吧这下衣服弄干的最短的时间
思路: 首先注意费就是数据,要longlong ,而且cin超时
对于烘干的速度是1 则不用多说,湿度最大的就是最慢的
其他情况 最快的方法也比较容易想,先举出一个时间数值,比这个数小的可以自己蒸发,
不用管他们,其余的就是先烘干一会,然后在烘干其他衣服是,之前烘过的蒸发干了  
判断当前mid分钟内是否完场就行了
推断 对于每一件衣服 k*t+(mid-t)>=map[i,得到t>=(map[i]–mid)/(k–1)
#include<iostream>#include<cmath>#include<stdio.h>using namespace std;long long  n,k;long long map[1000001];int judge(long long mid){    long long temp,t=0;    for(int i=0;i<n;i++)    {        if(map[i]>mid)        {            temp=(long long)ceil((map[i]-mid)*1.0/(k-1));            t+=temp;            }        if(t>mid)return 0;        }    return 1;    }int main(){    int i,j;    long long max;    char s[100];    while(scanf("%lld",&n)!=EOF)    {        max=0;        for(i=0;i<n;i++)        {            scanf("%lld",&map[i]);            if(max<map[i])            max=map[i];        }        scanf("%lld",&k);        if(k==1)        {            cout<<max<<endl;        }        else        {            long long ans,mid,low=1,high=max;            while(low<=high)            {                mid=(low+high)/2;                if(judge(mid))                {                    ans=mid;                    high=mid-1;                    }                else                    low=mid+1;                }            //cout<<s<<endl;            cout<<ans<<endl;            }        }    return 0;    }

原创粉丝点击