http://www.lydsy.com/JudgeOnline/problem.php?id=2016

这些最大最小显然是二分。

但是二分细节挺多的。。。这里注意二分的区间,可以累计所有的可能,然后这就是二分区间的右界。。(我是sb)

然后二分的时候,判断那里一定要仔细啊。。

还有这题要开longlong啊(雾)

  1. #include <cstdio>
  2. #include <cstring>
  3. #include <cmath>
  4. #include <string>
  5. #include <iostream>
  6. #include <algorithm>
  7. #include <queue>
  8. using namespace std;
  9. #define rep(i, n) for(int i=0; i<(n); ++i)
  10. #define for1(i,a,n) for(int i=(a);i<=(n);++i)
  11. #define for2(i,a,n) for(int i=(a);i<(n);++i)
  12. #define for3(i,a,n) for(int i=(a);i>=(n);--i)
  13. #define for4(i,a,n) for(int i=(a);i>(n);--i)
  14. #define CC(i,a) memset(i,a,sizeof(i))
  15. #define read(a) a=getint()
  16. #define print(a) printf("%d", a)
  17. #define dbg(x) cout << #x << " = " << x << endl
  18. #define printarr2(a, b, c) for1(i, 1, b) { for1(j, 1, c) cout << a[i][j]; cout << endl; }
  19. #define printarr1(a, b) for1(i, 1, b) cout << a[i]; cout << endl
  20. inline const int getint() { int r=0, k=1; char c=getchar(); for(; c<'0'||c>'9'; c=getchar()) if(c=='-') k=-1; for(; c>='0'&&c<='9'; c=getchar()) r=r*10+c-'0'; return k*r; }
  21. inline const int max(const int &a, const int &b) { return a>b?a:b; }
  22. inline const int min(const int &a, const int &b) { return a<b?a:b; }
  23.  
  24. typedef long long ll;
  25. const int N=50005;
  26. ll a[N];
  27. int n, d;
  28. bool check(ll x) {
  29. ll sum=0; int tot=1;
  30. for1(i, 1, n) {
  31. sum+=a[i];
  32. while(tot<=d && sum>=x) sum>>=1, ++tot;
  33. if(tot>d) return 1;
  34. }
  35. return 0;
  36. }
  37. void pri(ll x) {
  38. ll sum=0; int tot=1;
  39. for1(i, 1, n) {
  40. sum+=a[i]; printf("%d\n", tot);
  41. while(tot<d && sum>=x) sum>>=1, ++tot;
  42. }
  43. }
  44.  
  45. int main() {
  46. read(n); read(d);
  47. ll l=0, r=0;
  48. for1(i, 1, n) read(a[i]), r+=a[i];
  49. while(l<=r) {
  50. ll m=(l+r)>>1;
  51. if(check(m)) l=m+1;
  52. else r=m-1;
  53. }
  54. printf("%lld\n", l-1);
  55. pri(l-1);
  56. return 0;
  57. }

Description

贝西从大牛那里收到了N块巧克力。她不想把它们马上吃完,而是打算制定一个计划,

使得在接下来的D天里,她能够尽量地快乐。贝西的快乐指数可以用一个整数来衡量,一开始的时候是0,当她每天晚上睡觉的时候,快乐指数会减半(奇数时向下取整)。贝西把她的巧克力按照收到的时间排序,并坚持按照这个顺序来吃巧克力。当她吃掉第i块巧克力的时候,她的快乐指数会增加Hj。每天可以吃任意多块巧克力,如何帮助贝西合理安排,使得D天内她的最小快乐指数最大呢?

举个例子:假设一共有五块巧克力,贝西打算在五天时间内将它们吃完,每块巧克力提

供的快乐指数分别为10,40,13,22,7。则最好的方案如F:

起床时快乐指数

就寝时快乐指数

0
    25
    12
    12
    17

50
    25
    25
    34
    24

五天内的最小快乐指数为24,这是所有吃法中的最大值。

Input

  第一行:两个用空格分开的整数:N和D,1≤N.D≤50000
  第二行到第N+1行:第1+1行表示第i块巧克力提供的快乐指数Hj,1≤Hi≤1000000

Output

  第一行:单个整数,表示贝西在接下来D天内的最小快乐指数的最大值
  第二行到第N+1:在第i+l行有一个整数,代表贝西应该在哪一天吃掉第i块巧克力。
    如果有多种吃法,则输出按照词典序排序后最靠后的方案

Sample Input

55
10
40
13
22
7

Sample Output

24
1
1
3
4
5

HINT

Source

【BZOJ】2016: [Usaco2010]Chocolate Eating(二分)的更多相关文章

  1. BZOJ 2016: [Usaco2010]Chocolate Eating( 二分答案 )

    因为没注意到long long 就 TLE 了... 二分一下答案就Ok了.. ------------------------------------------------------------ ...

  2. BZOJ 2016: [Usaco2010]Chocolate Eating

    题目 2016: [Usaco2010]Chocolate Eating Time Limit: 10 Sec  Memory Limit: 162 MB Description 贝西从大牛那里收到了 ...

  3. bzoj 2016: [Usaco2010]Chocolate Eating【二分+贪心】

    二分答案,贪心判断,洛谷上要开long long #include<iostream> #include<cstdio> using namespace std; const ...

  4. 2016: [Usaco2010]Chocolate Eating

    2016: [Usaco2010]Chocolate Eating Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 224  Solved: 87[Su ...

  5. bzoj2016[Usaco2010]Chocolate Eating*

    bzoj2016[Usaco2010]Chocolate Eating 题意: n块巧克力,每次吃可以增加ai点快乐,每天早晨睡觉起来快乐值会减半,求如何使d天睡觉前的最小快乐值最大.n,d≤5000 ...

  6. [Usaco2010]Chocolate Eating

    题目描述 贝西从大牛那里收到了N块巧克力.她不想把它们马上吃完,而是打算制定一个计划, 使得在接下来的D天里,她能够尽量地快乐.贝西的快乐指数可以用一个整数来衡量,一开始的时候是0,当她每天晚上睡觉的 ...

  7. [USACO10FEB] 吃巧克力Chocolate Eating (二分答案)

    题目链接 Solution 先直接二分答案,然后贪心判断,一旦少于答案就吃一块. 思路很简单,有一点细节. 一天内可以不吃巧克力. 注意处理最后时没吃完的全部在最后一天吃完. Code #includ ...

  8. P2985 [USACO10FEB]吃巧克力Chocolate Eating

    P2985 [USACO10FEB]吃巧克力Chocolate Eating 题目描述 Bessie has received N (1 <= N <= 50,000) chocolate ...

  9. NC24724 [USACO 2010 Feb S]Chocolate Eating

    NC24724 [USACO 2010 Feb S]Chocolate Eating 题目 题目描述 Bessie has received \(N (1 <= N <= 50,000)\ ...

随机推荐

  1. 倍福TwinCAT(贝福Beckhoff)常见问题(FAQ)-如何添加自定义Task,如何让程序的一部分拥有不同的执行周期

    右击Tasks,添加一个新的Task,可以设置这个新的任务的扫描周期,比如100ms   右击PLC的整个的Project,然后Add一个Referenced Task,选中你新建的Task   在P ...

  2. js中,{}初始化数据类型object;for in 的用法;delete的用法

    var choices = {}; //此数据表示的是:object{} for(var i=0;i<10;i++){ choices[i+1] = [data[i].testPlan,test ...

  3. "no talloc stackframe at ../source3/param/loadparm.c:4864, leaki

    This problem related to the samba PAM module. You have 2 solution at all. Solution 1#: Remove it( as ...

  4. Java中Object转化为int类型

    转自:http://blog.sina.com.cn/s/blog_5f8421fb010162kb.html Java中由Object类型转化为int类型时,不能直接转化,先是将Object类型转化 ...

  5. MySQL外键的设置及作用

    原文地址:http://www.php100.com/html/webkaifa/database/Mysql/2010/0830/5342.html 外键的作用: 保持数据一致性,完整性,主要目的是 ...

  6. jconsole JDK1.6 使用手册 (转)

    转载出处 文章作者:hornet 本文地址:http://hornetblog.sinaapp.com/?p=5 英文版地址: http://download.oracle.com/javase/6/ ...

  7. 忽略警告注解@SuppressWarnings详解

    简介:java.lang.SuppressWarnings是J2SE 5.0中标准的Annotation之一.可以标注在类.字段.方法.参数.构造方法,以及局部变量上. 作用:告诉编译器忽略指定的警告 ...

  8. 接收广播BroadcastReceiver

    Broadcast Receiver用于接收并处理广播通知(broadcast announcements).多数的广播是系统发起的,如地域变换.电量不足.来电来信等.程序也可以播放一个广播.程序可以 ...

  9. iloc[[i]] 和 loc[[i]] 的区别

    In [2]: df Out[2]: A B 0 1.068932 -0.794307 2 -0.470056 1.192211 4 -0.284561 0.756029 6 1.037563 -0. ...

  10. redis安装和配置(一)

    Redis 的官方下载站是http://redis.io/download 怎么安装 Redis 数据库呢?下面将介绍Linux 版本的安装方法 步骤一: 下载Redis 下载安装包:wget htt ...