zoukankan      html  css  js  c++  java
  • poj3104 Drying

    思路:

    二分。

    实现:

     1 #include <cstdio>
     2 #include <algorithm>
     3 using namespace std;
     4 typedef long long ll;
     5 const int MAXN = 100005;
     6 int a[MAXN], n, k;
     7 int Ceil(int a, int c)
     8 {
     9     return (a + c - 1) / c;
    10 }
    11 bool check(int x)
    12 {
    13     ll tot = 0;
    14     for (int i = 0; i < n; i++)
    15     {
    16         if (a[i] > x) tot += Ceil(a[i] - x, k - 1);
    17         if (tot > x) return false;
    18     }
    19     return true;
    20 }
    21 int main()
    22 {
    23     scanf("%d", &n);
    24     int maxn = 0;
    25     for (int i = 0; i < n; i++) 
    26     { 
    27         scanf("%d", &a[i]); 
    28         maxn = max(maxn, a[i]); 
    29     }
    30     scanf("%d", &k);
    31     if (k == 1) { printf("%d
    ", maxn); return 0; }
    32     int l = 1, r = maxn, ans = maxn;
    33     while (l <= r)
    34     {
    35         int m = (l + r) >> 1;
    36         if (check(m))
    37         {
    38             ans = m; r = m - 1;
    39         }
    40         else l = m + 1;
    41     }
    42     printf("%d
    ", ans);
    43     return 0;
    44 }
  • 相关阅读:
    PHP面试题4
    php面试题2
    php基础面试题1
    mysql添加索引命令
    lnmp初步学习知识整理
    代码运行的自由
    Lein droid
    关于Domain Sepcific Lang
    JavaScript倒计时类
    三国小记
  • 原文地址:https://www.cnblogs.com/wangyiming/p/8328742.html
Copyright © 2011-2022 走看看