zoukankan      html  css  js  c++  java
  • 【二分答案】BZOJ2016-Chocolate Eating

    【题目大意】

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

    【思路】

    二分每天的最小快乐值,只要没有达到快乐值就继续吃。

    不知道为什么了WA了8发..8发??!!!!说好的水题呢??!!!而且我也不知道哪里错了反正突然AC了??!!

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 #include<algorithm>
     5 using namespace std;
     6 const int MAXN=100000+50;
     7 typedef long long ll;
     8 int n,d;
     9 ll h[MAXN];
    10 ll ans[MAXN],tmp[MAXN];
    11 ll ansx;
    12 
    13 void init()
    14 {
    15     scanf("%d%d",&n,&d);
    16     for (int i=1;i<=n;i++) scanf("%lld",&h[i]);
    17 } 
    18 
    19 int check(ll x)
    20 {
    21     int j=1;
    22     ll sum=0;
    23     for (int i=1;i<=d;i++)
    24     {
    25         while (sum<x && j<=n)
    26         {
    27             tmp[j]=i;
    28             sum+=h[j++];
    29         } 
    30         if (sum<x) return 0;
    31         sum>>=1;
    32     }
    33     while (j<=n) tmp[j++]=d;
    34     for (int i=1;i<=n;i++) ans[i]=tmp[i];
    35     ansx=x;
    36     return 1;
    37 }
    38 
    39 void solve()
    40 {
    41     ll lb=1,ub=50000000000ll;
    42     while (lb<=ub)
    43     {
    44         ll mid=(lb+ub)>>1;
    45         if (check(mid)) lb=mid+1;else ub=mid-1;
    46     }
    47     printf("%lld
    ",ansx);
    48     for (int i=1;i<=n;i++) 
    49         printf("%lld
    ",ans[i]); 
    50 }
    51 
    52 int main()
    53 {
    54     init();
    55     solve();
    56     return 0;
    57 } 
  • 相关阅读:
    [省选联考 2020 A 卷] 组合数问题
    [HAOI2018]苹果树
    [集训队作业2013]城市规划
    多项式牛顿迭代
    多项式开方
    分治 FFT 模板的三种过法
    Graham 求静态凸包
    exp 初探
    HAOI2018 染色
    如何关闭wps热点,如何关闭wpscenter,如何关闭我的wps
  • 原文地址:https://www.cnblogs.com/iiyiyi/p/5772612.html
Copyright © 2011-2022 走看看