【BZOJ】2016: [Usaco2010]Chocolate Eating(二分)
http://www.lydsy.com/JudgeOnline/problem.php?id=2016
这些最大最小显然是二分。
但是二分细节挺多的。。。这里注意二分的区间,可以累计所有的可能,然后这就是二分区间的右界。。(我是sb)
然后二分的时候,判断那里一定要仔细啊。。
还有这题要开longlong啊(雾)
- #include <cstdio>
- #include <cstring>
- #include <cmath>
- #include <string>
- #include <iostream>
- #include <algorithm>
- #include <queue>
- using namespace std;
- #define rep(i, n) for(int i=0; i<(n); ++i)
- #define for1(i,a,n) for(int i=(a);i<=(n);++i)
- #define for2(i,a,n) for(int i=(a);i<(n);++i)
- #define for3(i,a,n) for(int i=(a);i>=(n);--i)
- #define for4(i,a,n) for(int i=(a);i>(n);--i)
- #define CC(i,a) memset(i,a,sizeof(i))
- #define read(a) a=getint()
- #define print(a) printf("%d", a)
- #define dbg(x) cout << #x << " = " << x << endl
- #define printarr2(a, b, c) for1(i, 1, b) { for1(j, 1, c) cout << a[i][j]; cout << endl; }
- #define printarr1(a, b) for1(i, 1, b) cout << a[i]; cout << endl
- 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; }
- inline const int max(const int &a, const int &b) { return a>b?a:b; }
- inline const int min(const int &a, const int &b) { return a<b?a:b; }
- typedef long long ll;
- const int N=50005;
- ll a[N];
- int n, d;
- bool check(ll x) {
- ll sum=0; int tot=1;
- for1(i, 1, n) {
- sum+=a[i];
- while(tot<=d && sum>=x) sum>>=1, ++tot;
- if(tot>d) return 1;
- }
- return 0;
- }
- void pri(ll x) {
- ll sum=0; int tot=1;
- for1(i, 1, n) {
- sum+=a[i]; printf("%d\n", tot);
- while(tot<d && sum>=x) sum>>=1, ++tot;
- }
- }
- int main() {
- read(n); read(d);
- ll l=0, r=0;
- for1(i, 1, n) read(a[i]), r+=a[i];
- while(l<=r) {
- ll m=(l+r)>>1;
- if(check(m)) l=m+1;
- else r=m-1;
- }
- printf("%lld\n", l-1);
- pri(l-1);
- return 0;
- }
Description
贝西从大牛那里收到了N块巧克力。她不想把它们马上吃完,而是打算制定一个计划,
使得在接下来的D天里,她能够尽量地快乐。贝西的快乐指数可以用一个整数来衡量,一开始的时候是0,当她每天晚上睡觉的时候,快乐指数会减半(奇数时向下取整)。贝西把她的巧克力按照收到的时间排序,并坚持按照这个顺序来吃巧克力。当她吃掉第i块巧克力的时候,她的快乐指数会增加Hj。每天可以吃任意多块巧克力,如何帮助贝西合理安排,使得D天内她的最小快乐指数最大呢?
举个例子:假设一共有五块巧克力,贝西打算在五天时间内将它们吃完,每块巧克力提
供的快乐指数分别为10,40,13,22,7。则最好的方案如F:
起床时快乐指数 |
就寝时快乐指数 |
0 |
50 |
五天内的最小快乐指数为24,这是所有吃法中的最大值。
Input
Output
Sample Input
10
40
13
22
7
Sample Output
1
1
3
4
5
HINT
Source
【BZOJ】2016: [Usaco2010]Chocolate Eating(二分)的更多相关文章
- BZOJ 2016: [Usaco2010]Chocolate Eating( 二分答案 )
因为没注意到long long 就 TLE 了... 二分一下答案就Ok了.. ------------------------------------------------------------ ...
- BZOJ 2016: [Usaco2010]Chocolate Eating
题目 2016: [Usaco2010]Chocolate Eating Time Limit: 10 Sec Memory Limit: 162 MB Description 贝西从大牛那里收到了 ...
- bzoj 2016: [Usaco2010]Chocolate Eating【二分+贪心】
二分答案,贪心判断,洛谷上要开long long #include<iostream> #include<cstdio> using namespace std; const ...
- 2016: [Usaco2010]Chocolate Eating
2016: [Usaco2010]Chocolate Eating Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 224 Solved: 87[Su ...
- bzoj2016[Usaco2010]Chocolate Eating*
bzoj2016[Usaco2010]Chocolate Eating 题意: n块巧克力,每次吃可以增加ai点快乐,每天早晨睡觉起来快乐值会减半,求如何使d天睡觉前的最小快乐值最大.n,d≤5000 ...
- [Usaco2010]Chocolate Eating
题目描述 贝西从大牛那里收到了N块巧克力.她不想把它们马上吃完,而是打算制定一个计划, 使得在接下来的D天里,她能够尽量地快乐.贝西的快乐指数可以用一个整数来衡量,一开始的时候是0,当她每天晚上睡觉的 ...
- [USACO10FEB] 吃巧克力Chocolate Eating (二分答案)
题目链接 Solution 先直接二分答案,然后贪心判断,一旦少于答案就吃一块. 思路很简单,有一点细节. 一天内可以不吃巧克力. 注意处理最后时没吃完的全部在最后一天吃完. Code #includ ...
- P2985 [USACO10FEB]吃巧克力Chocolate Eating
P2985 [USACO10FEB]吃巧克力Chocolate Eating 题目描述 Bessie has received N (1 <= N <= 50,000) chocolate ...
- NC24724 [USACO 2010 Feb S]Chocolate Eating
NC24724 [USACO 2010 Feb S]Chocolate Eating 题目 题目描述 Bessie has received \(N (1 <= N <= 50,000)\ ...
随机推荐
- 倍福TwinCAT(贝福Beckhoff)常见问题(FAQ)-如何添加自定义Task,如何让程序的一部分拥有不同的执行周期
右击Tasks,添加一个新的Task,可以设置这个新的任务的扫描周期,比如100ms 右击PLC的整个的Project,然后Add一个Referenced Task,选中你新建的Task 在P ...
- js中,{}初始化数据类型object;for in 的用法;delete的用法
var choices = {}; //此数据表示的是:object{} for(var i=0;i<10;i++){ choices[i+1] = [data[i].testPlan,test ...
- "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 ...
- Java中Object转化为int类型
转自:http://blog.sina.com.cn/s/blog_5f8421fb010162kb.html Java中由Object类型转化为int类型时,不能直接转化,先是将Object类型转化 ...
- MySQL外键的设置及作用
原文地址:http://www.php100.com/html/webkaifa/database/Mysql/2010/0830/5342.html 外键的作用: 保持数据一致性,完整性,主要目的是 ...
- jconsole JDK1.6 使用手册 (转)
转载出处 文章作者:hornet 本文地址:http://hornetblog.sinaapp.com/?p=5 英文版地址: http://download.oracle.com/javase/6/ ...
- 忽略警告注解@SuppressWarnings详解
简介:java.lang.SuppressWarnings是J2SE 5.0中标准的Annotation之一.可以标注在类.字段.方法.参数.构造方法,以及局部变量上. 作用:告诉编译器忽略指定的警告 ...
- 接收广播BroadcastReceiver
Broadcast Receiver用于接收并处理广播通知(broadcast announcements).多数的广播是系统发起的,如地域变换.电量不足.来电来信等.程序也可以播放一个广播.程序可以 ...
- 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. ...
- redis安装和配置(一)
Redis 的官方下载站是http://redis.io/download 怎么安装 Redis 数据库呢?下面将介绍Linux 版本的安装方法 步骤一: 下载Redis 下载安装包:wget htt ...