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. python模块详解 XML

    XML模块 XML是实现不同语言或程序之间进行数据交换的协议,和json一样. XML格式: <?xml version="1.0" encoding="UTF-8 ...

  2. tomcat下部署项目的流程和遇到的问题笔记

    简单部署流程: 1,解析域名关联到服务器ip 2,配置服务器jre运行环境 3,安装tomcat 4,项目打war包,放入tomcat根目录下webapps(tomcat默认加载的项目目录)目录下 5 ...

  3. 如何将centos7自带的firewall防火墙更换为iptables防火墙

    用惯了centos6的iptables防火墙,对firewall太无感了,那么如何改回原来熟悉的iptables防火墙呢? 1.关闭firewall防火墙 [root@centos7 html]# s ...

  4. leetcode: 数组

    1. longest-consecutive-sequence Given an unsorted array of integers, find the length of the longest ...

  5. Selenium入门系列4 选择并操作一组元素

    选中一组元素的方式也是8种,与选中单个元素一一对应.区别只在于element与elements.elements取到的是一个数组,element取符合条件的第一个元素. 首先在脚本的目录下新建test ...

  6. 【洛谷4717】【模板】快速沃尔什变换(FWT模板)

    点此看题面 大致题意: 有两个长度为\(2^n\)的数组\(A,B\),且\(C_i=\sum_{j⊕k==i}A_jB_k\)分别求出当\(⊕\)为\(or,and,xor\)时的\(C\)数组. ...

  7. Java nio socket与as3 socket(粘包解码)连接的应用实例

    对Java nio socket与as3 socket连接的简单应用 <ignore_js_op>Java nio socket与as3 socket连接的应用实例.rar (9.61 K ...

  8. 编译安装 mysql 5.5,运行 cmake报错Curses library not found

    是因为 curses库没有安装,执行下面的语句即可 yum -y install ncurses-devel 如果上述命令的结果是no package,则使用下面的命令安装 apt-get insta ...

  9. 2017.11.11 详谈application、session、request和page的作用范围

    今天在图书馆遇到了问题 不知道怎么选择session还是request Web应用中的JSP和servlet都是由web服务器来调用,Jsp和Servlet之间通常不会相互调用,那么Jsp和Servl ...

  10. layui table 用法

    1.使用模板列 改变样式 获取嵌套数据{ field: '', width: '12%', title: '响应状态', sort: true, templet: function (d) { if ...