bzoj2016[Usaco2010]Chocolate Eating*

bzoj2016[Usaco2010]Chocolate Eating

题意:

n块巧克力,每次吃可以增加ai点快乐,每天早晨睡觉起来快乐值会减半,求如何使d天睡觉前的最小快乐值最大。n,d≤50000

题解:

二分快乐值,每天不够就吃。注意如果最后一天有剩余巧克力,必须将其全部吃完。

代码:

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <algorithm>
 4 #define ll long long
 5 #define inc(i,j,k) for(int i=j;i<=k;i++)
 6 #define maxn 100010
 7 using namespace std;
 8 
 9 inline ll read(){
10     char ch=getchar(); ll f=1,x=0;
11     while(ch<'0'||ch>'9'){if(ch=='-')f=-1; ch=getchar();}
12     while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
13     return f*x;
14 }
15 int n,d,bel[maxn]; ll h[maxn],ans1,ans2[maxn];
16 bool check(ll x){
17     ll hap=0; int p=1;
18     inc(i,1,d){
19         while(hap<x&&p<=n)hap+=h[p],bel[p]=i,p++; if(hap<x)return 0; hap>>=1;
20     }
21     while(p<=n)bel[p]=d,p++; inc(i,1,n)ans2[i]=bel[i]; ans1=x; return 1;
22 }
23 int main(){
24     n=read(); d=read(); inc(i,1,n)h[i]=read();
25     ll l=1,r=50000000000LL;
26     while(l<=r){
27         ll mid=(l+r)>>1; if(check(mid))l=mid+1;else r=mid-1;
28     }
29     printf("%lld\n",ans1); inc(i,1,n)printf("%lld\n",ans2[i]);
30 }

 

20160811

转载于:https://www.cnblogs.com/YuanZiming/p/5771570.html

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值