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
    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. 手机端UC浏览器,在java开发的下载功能中存在的问题?

    在java web开发中,不同浏览器对下载文件的格式有不同的要求,有时会出现视频,音频等文件无法下载的问题.我在开发中,也遇到类似的问题,觉得很苦恼. 经过百度和请教学习,得到2个解决方案. 首先得到 ...

  2. Bitmap和Drawable的互相转换

    刚好之前的项目实用到.怕遗忘了.就先记录下来.然后会用到的时候直接来这copy使用就好了. 1.Bitmap ---->Drawable: public static Drawable bitm ...

  3. android 从Activity 获取 rootView 根节点

    private static View getRootView(Activity context) { return ((ViewGroup)context.findViewById(android. ...

  4. ECMAScript6 | 新特性(部分)

    新特性概览 参考文章:http://www.cnblogs.com/Wayou/p/es6_new_features.html 这位前辈写的很好,建议深入学习 ———————————————————— ...

  5. esriControlsMousePointer常量

    控制鼠标指针选项. 不变 值 描述 esriPointerParentWindow -1 指针指定的父窗口或窗体. esriPointerDefault 0 默认指针,箭头一样. esriPointe ...

  6. jmeter-BeanShell Sampler

    https://www.cnblogs.com/ShadowXie/p/6025941.html

  7. andorid HTTPS 不需要证书 VolleyEror: com.android.volley.NoConnectionError: javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not fou

    1.加证书(这里不说) 2.修改代码 import java.security.KeyManagementException;import java.security.NoSuchAlgorithmE ...

  8. Nav titleView 设置的两个方式

    1.self.navigationItem.titleView = vv; 2.[self.navigationController.navigationBar addSubview:vv];

  9. navigate是Router类的一个方法,主要用来跳转路由。

    navigate是Router类的一个方法,主要用来跳转路由. 1 2 3 4 5 6 7 8 9 interface NavigationExtras {  relativeTo : Activat ...

  10. Xcode5下使用纯代码构建简单的HelloWorld程序

    转自:http://blog.csdn.net/developerxyf/article/details/12874935 新发布的Xcode5在使用模板创建工程的时候取消了以往是否要选择storyb ...