P2985 [USACO10FEB]吃巧克力Chocolate Eating

题目描述

Bessie has received N (1 <= N <= 50,000) chocolates from the bulls, but doesn't want to eat them too quickly, so she wants to plan out her chocolate eating schedule for the next D (1 <= D <= 50,000) days in order to maximize her minimum happiness level over the set of those days.

Bessie's happiness level is an integer that starts at 0 and halves (rounding down if necessary) over night as she sleeps. However, when she eats chocolate i, her happiness level increases by integer H_i (1 <= H_i <= 1,000,000). If she eats chocolates on a day, her happiness for that day is considered the happiness level after she eats the chocolates. Bessie insists that she eat the chocolates in the order that she received them.

If more than one optimal solution exists, print any one of them.

Consider a sequence of 5 chocolates to be eaten over a period of 5 days; they respectively bring happiness (10, 40, 13, 22, 7).

If Bessie eats the first chocolate (10 happiness) on the first day and then waits to eat the others, her happiness level is 10 after the first day.

Here is the complete schedule which turns out to maximize her minimum happiness:

Day Wakeup happiness Happiness from eating Bedtime happiness 1 0 10+40 50

2 25 --- 25

3 12 13 25

4 12 22 34

5 17 7 24

The minimum bedtime happiness is 24, which turns out to be the best Bessie can do.

Bessie拿到了N (1 <= N <= 50,000)块巧克力。她决定想个办法吃掉这些巧克力,使得它在吃巧克力的这段时间里,最不开心的一天尽可能的开心。并且一共吃D (1 <= D <= 50,000)天。

每块巧克力有一个开心值H_i (1 <= H_i <= 1,000,000),当某天你吃下那块巧克力时,你将获得那块巧克力的开心值。每一天的开心值是所有当天吃掉的巧克力的总开心值之和。每天晚上Bessie睡觉之后,它的开心值会减半。也就是说,比如昨天Bessie的开心值为50,那么今天早上我一醒来我就会有25点的开心值,舍去小数点后数字。另外,Bessie还有一个怪癖,她喜欢按照巧克力本来的排列顺序吃。

Bessie第一天的开心值为0,求一个每天吃巧克力的方案,使得Bessie最不开心的一天尽可能的开心。

输入输出格式

输入格式:

  • Line 1: Two space separated integers: N and D

  • Lines 2..N+1: Line i+1 contains a single integer: H_i

输出格式:

  • Line 1: A single integer, the highest Bessie's minimum happiness can be over the next D days

  • Lines 2..N+1: Line i+1 contains an integer that is the day on which Bessie eats chocolate i

输入输出样例

输入样例#1:

5 5
10
40
13
22
7
输出样例#1:

24
1
1
3
4
5
一道二分的题,坑点太多,一直过不了QAQ。
注意:1、居然忘记输出巧克力在那一天吃了,直接输出二分答案!!!2、开long long 就是开了9行开了吗!!!3、吃不完的最后一天吃,直接忽略orz!!!
 #include<cstdio>
#include<cstring>
long long c[];
int v[];
int n,m;
bool check(long long x,bool flag)
{
int p = ;
long long now = ; //这里也要开long long !!!
for (int i=; i<=m; ++i)
{
now = now>>;
while (now<x&&p<=n)
{
++p;
if (flag) v[p] = i;
now += c[p];
}
if (now<x) return false ;
}
if (flag)
for (int i=p+; i<=n; ++i) //多余的都在最后一天吃
v[i] = m;
return true ;
}
int main()
{
long long ans = , l = , r = ;
scanf("%d%d",&n,&m);
for (int i=; i<=n; ++i)
{
scanf("%lld",&c[i]);
r += c[i];
}
while (l<=r)
{
long long mid = (l+r)>>;
if (check(mid,))
{
ans = mid;
l = mid+;
}
else r = mid-;
}
printf("%lld\n",ans);
check(ans,); //求出巧克力在那一天吃
for (int i=; i<=n; ++i)
printf("%d\n",v[i]);
return ;
}

P2985 [USACO10FEB]吃巧克力Chocolate Eating的更多相关文章

  1. luogu P2985 [USACO10FEB]吃巧克力Chocolate Eating

    题目描述 Bessie拿到了N (1 <= N <= 50,000)块巧克力.她决定想个办法吃掉这些巧克力,使得它在吃巧克力的这段时间里,最不开心的一天尽可能的开心.并且一共吃D (1 & ...

  2. [USACO10FEB]吃巧克力Chocolate Eating

    题目:洛谷P2985. 题目大意:有n块巧克力要吃d天,并且只能按顺序吃.一块巧克力有一个开心值,吃了就能增加开心值.一个人初始开心值为0,且每天早上开心值变为原来的一半.问如何吃巧克力才能使开心值最 ...

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

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

  4. 洛谷——P2983 [USACO10FEB]购买巧克力Chocolate Buying

    P2983 [USACO10FEB]购买巧克力Chocolate Buying 题目描述 Bessie and the herd love chocolate so Farmer John is bu ...

  5. 洛谷 P2983 [USACO10FEB]购买巧克力Chocolate Buying 题解

    P2983 [USACO10FEB]购买巧克力Chocolate Buying 题目描述 Bessie and the herd love chocolate so Farmer John is bu ...

  6. 洛谷 P2983 [USACO10FEB]购买巧克力Chocolate Buying

    购买巧克力Chocolate Buying 乍一看以为是背包,然后交了一个感觉没错的背包上去. #include <iostream> #include <cstdio> #i ...

  7. P2983 [USACO10FEB]购买巧克力Chocolate Buying

    题目描述 Bessie and the herd love chocolate so Farmer John is buying them some. The Bovine Chocolate Sto ...

  8. 【洛谷】P2983 [USACO10FEB]购买巧克力Chocolate Buying(贪心)

    题目描述 Bessie and the herd love chocolate so Farmer John is buying them some. The Bovine Chocolate Sto ...

  9. 洛谷P2983 [USACO10FEB]购买巧克力Chocolate Buying

    题目描述 Bessie and the herd love chocolate so Farmer John is buying them some. The Bovine Chocolate Sto ...

随机推荐

  1. 用HttpSessionListener统计在线用户或做账号在线人数管理

    使用HttpSessionListener接口可监听session的创建和失效 session是在用户第一次访问页面时创建 在session超时或调用request.getSession().inva ...

  2. check_mk检测插件 - raid监控

    mk_raidstatus python版本 #!/usr/bin/env python # -*- encoding: utf-8; py-indent-offset: 4 -*- import s ...

  3. mouse事件在JQ中的应用(在动画与交互中用得比较多).

    mousedown与mouseup事件 用户交互操作中,最简单直接的操作就是点击操作,因此jQuery提供了一个mousedown的快捷方法可以监听用户鼠标按下的操作,与其对应的还有一个方法mouse ...

  4. 如何下载YouTube 8K视频

    随着科技的进步,人们对高清视频的要求越来越高,因此视频的分辨率也越来越高.从最开始的720P,到1080P,再到2K,进而到如今4K,不断地满足人们挑剔的胃口.4K分辨率的视频已经逐渐进入人们的生活中 ...

  5. Android(java)学习笔记61:Android中的 Application类用法

    1. 简介 如果想在整个应用中使用全局变量,在java中一般是使用静态变量,public类型:而在android中如果使用这样的全局变量就不符合Android的框架架构,但是可以使用一种更优雅的方式就 ...

  6. python 面向对象(三)--继承和多态

    在OOP程序设计中,当我们定义一个class的时候,可以从某个现有的class继承,新的class称为子类(Subclass),而被继承的class称为基类.父类或超类(Base class.Supe ...

  7. C++STL之vector向量容器

    vector向量容器   vector向量容器不但能向数组一样对元素进行随机访问, 还能在尾部插入元素 vector具有内存自动管理的功能, 对于元素的插入和删除, 可动态调整所占的内存空间 vect ...

  8. 2017.10.5 Java图形化界面设计——布局管理器

    1.BorderLayout(边界布局) 边界布局管理器把容器的的布局分为五个位置:CENTER.EAST.WEST.NORTH.SOUTH.依次对应为:上北(NORTH).下南(SOUTH).左西( ...

  9. CNMeM is disabled

    See here: http://deeplearning.net/software/theano/library/config.html You can change this in the env ...

  10. 图像上采样(图像插值)增取样(Upsampling)或内插(Interpolating)下采样(降采样),

    缩小图像(或称为下采样(subsampled)或降采样(downsampled))的主要目的有两个:1.使得图像符合显示区域的大小:2.生成对应图像的缩略图.放大图像(或称为上采样(upsamplin ...