zoukankan      html  css  js  c++  java
  • Drying POJ

      

      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

    1.不要随便用upper_bound,如果你没理解清楚的话~~~(wa了十多次)
    2.二分答案再验证,在验证的时候注意方法~~~
     1 #include<iostream>
     2 #include<algorithm>
     3 #include<cstdio>
     4 #include<string>
     5 #define MAX 100005
     6 using namespace std;
     7 typedef long long ll;
     8 
     9 ll n,m;
    10 ll a[MAX];
    11 
    12 bool check(int k){
    13     ll cnt=0;
    14     //ll pos=upper_bound(a+1,a+n+1,k)-a-1;
    15     //if(pos==0) pos++;
    16     for(int i=1;i<=n;i++){
    17         if(a[i]>k){
    18            cnt+=(a[i]-k)/(m-1);
    19            if((a[i]-k)%(m-1)!=0) cnt++;
    20            if(cnt>k) return false;
    21         }
    22     }
    23     return true;
    24 }
    25 int main()
    26 {  
    27    while(~scanf("%lld",&n)){
    28         for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
    29         sort(a+1,a+n+1);
    30         scanf("%lld",&m);
    31         if(m==1) printf("%lld
    ",a[n]);
    32         else{
    33             ll l=1,r=a[n];
    34             while(r-l>1){
    35                    ll mid=(l+r)/2;
    36                    if(check(mid)) r=mid;
    37                    else l=mid;
    38             } 
    39             if(check(l)) printf("%lld
    ",l);
    40             else printf("%lld
    ",r);
    41         }
    42     }
    43     return 0;
    44 }
  • 相关阅读:
    paip.调用GUI接口.
    paip.按键替换映射总结
    paip.IIS 7.5 应用程序池,应用程序以及虚拟目录的存储位置
    paip.android 手机输入法制造大法
    paip.设置鼠标灵敏度API
    paip.系统无法在消息文件中为 Application 找到消息号为 0x2350 的消息文本。服务器存储空间不足,无法处理此命令
    paip.DEVSUIT WEB .NET ASPX网站打开慢的原因
    paip.动画透明淡入淡出窗口之重绘性能
    PAIP。JS调用DLL的解决方案
    paip.输入法编程四级非常用汉字汉字1000个
  • 原文地址:https://www.cnblogs.com/zgglj-com/p/6769666.html
Copyright © 2011-2022 走看看