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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值