hiho1095(二分)

题目连接:https://hihocoder.com/problemset/problem/1095

应该是之前在哪看的代码。不像是我写的。。

 1 #include <iostream>
 2 using namespace std;
 3 const int MAXN=100005;
 4 const int INF=0x3f3f3f3f;
 5 int n,k;
 6 int d[MAXN];
 7 bool test(int T)
 8 {
 9     int cup=0;
10     int hi_score=0;
11     int ho_score=0;
12     for(int i=0;i<n;i++)
13     {
14         cup+=T;
15         if(cup<=d[i])
16         {
17             hi_score++;
18             cup=0;
19         }
20         else
21         {
22             ho_score++;
23             cup-=d[i];
24         }
25     }
26     return ho_score>hi_score;
27 }
28 int main()
29 {
30     cin>>n>>k;
31     for(int i=0;i<n;i++)
32     {
33         cin>>d[i];
34     }
35     int l=0,r=INF;
36     while(r-l>1)
37     {
38         int mid=(l+r)>>1;
39         if(test(mid))
40         {
41             r=mid;
42         }
43         else
44         {
45             l=mid;
46         }
47     }
48     cout<<r<<endl;
49     return 0;
50 }
原文地址:https://www.cnblogs.com/yijiull/p/6746546.html