• poj 3104 Drying(二分查找)


                                           Drying
    Time Limit: 2000MS   Memory Limit: 65536K
    Total Submissions: 9440   Accepted: 2407

    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
    题目大意:有n件衣服,每件衣服有一定的水量,使衣服干有两种方法:1、水分蒸发,每分钟蒸发掉一滴水 2、用烘干机烘干,每分钟烘干掉k滴水。题目要输出的是是所有衣服变干的最小时间。

    详见代码。
     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cmath>
     4 
     5 using namespace std;
     6 
     7 #define ll long long
     8 
     9 int main ()
    10 {
    11     int n;
    12     ll a[100000+10];
    13     ll tmax;
    14     while (~scanf("%d",&n))
    15     {
    16         tmax=0;
    17         for (int i=0; i<n; i++)
    18         {
    19             scanf("%lld",&a[i]);
    20             if (a[i]>tmax)
    21                 tmax=a[i];
    22         }
    23         ll k;
    24         scanf("%lld",&k);
    25         if (k==1)
    26         {
    27             printf ("%lld",tmax);
    28             continue;
    29         }
    30         ll l=1,r=tmax,mid,ans=0;
    31         while (r>=l)
    32         {
    33             ll sum=0;
    34             mid=(l+r)/2;
    35             for (int i=0;i<n;i++)
    36             {
    37                 if(a[i]>mid)
    38                 {
    39                     ll s=ceil((a[i]-mid)*1.0/(k-1));
    40                     sum+=s;
    41                 }
    42             }
    43             if (sum>mid)
    44                 l=mid+1;
    45             else
    46                 r=mid-1,ans=mid;
    47         }
    48         printf ("%lld
    ",ans);
    49     }
    50     return 0;
    51 }
    
    
    
     
  • 相关阅读:
    (树的直径)第九届湘潭市大学生程序设计比赛 H-Highway
    (记忆化DFS)Codeforces Round #413 D-Field expansion
    (树状数组)Codeforces Round #413 C-Fountains
    (几何)LeetCode Weekly Contest 32 D-Erect the Fence
    LeetCode Weekly Contest 32 解题报告
    (贪心)华师大程序设计竞赛 F-丽娃河的狼人传说
    (最短路)AtCoder Beginner Contest 061 D
    Tinkoff Challenge
    Codeforces Round #410 (Div. 2) 解题报告
    (二叉树)UVA
  • 原文地址:https://www.cnblogs.com/qq-star/p/4259173.html
Copyright © 2020-2023  润新知