POJ 3232 Accelerator

二分

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <cstdlib>
 4 #include <algorithm>
 5 
 6 #define LL long long int
 7 
 8 using namespace std;
 9 
10 const int MAXN = 100010;
11 
12 LL a[MAXN];
13 LL M, K;
14 int N;
15 
16 bool check( LL mid )
17 {
18     LL TotUse = mid * M;
19     LL use = 0;
20     for ( int i = 0; i < N; ++i )
21     {
22         if ( a[i] <= mid ) continue;
23         if ( mid * K < a[i] ) return false;
24 
25         LL tp = ( a[i] - mid ) / ( K - 1 );
26         if ( ( a[i] - mid ) % ( K - 1 ) ) ++tp;
27         use += tp;
28     }
29     return use <= TotUse;
30 }
31 
32 int main()
33 {
34     int T;
35    // freopen( "s.out", "w", stdout );
36     scanf( "%d", &T );
37     while ( T-- )
38     {
39         LL high = -1;
40         scanf( "%d", &N );
41         for ( int i = 0; i < N; ++i )
42         {
43             scanf( "%I64d", &a[i] );
44             high = max( high, a[i] );
45         }
46         scanf( "%I64d%I64d", &M, &K );
47         if ( K == 1 )
48         {
49             printf( "%I64d\n", high );
50             continue;
51         }
52 
53         LL l = 1, r = high;
54         LL mid;
55         while ( l < r )
56         {
57             mid = ( l + r ) >> 1;
58             if ( check( mid ) )
59             {
60                 r = mid;
61             }
62             else l = mid + 1;
63         }
64         printf( "%I64d\n", l );
65     }
66     return 0;
67 }

 

转载于:https://www.cnblogs.com/GBRgbr/archive/2013/04/24/3041043.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值