P2985 [USACO10FEB]吃巧克力Chocolate Eating
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
输入输出样例
5 5
10
40
13
22
7
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的更多相关文章
- luogu P2985 [USACO10FEB]吃巧克力Chocolate Eating
题目描述 Bessie拿到了N (1 <= N <= 50,000)块巧克力.她决定想个办法吃掉这些巧克力,使得它在吃巧克力的这段时间里,最不开心的一天尽可能的开心.并且一共吃D (1 & ...
- [USACO10FEB]吃巧克力Chocolate Eating
题目:洛谷P2985. 题目大意:有n块巧克力要吃d天,并且只能按顺序吃.一块巧克力有一个开心值,吃了就能增加开心值.一个人初始开心值为0,且每天早上开心值变为原来的一半.问如何吃巧克力才能使开心值最 ...
- [USACO10FEB] 吃巧克力Chocolate Eating (二分答案)
题目链接 Solution 先直接二分答案,然后贪心判断,一旦少于答案就吃一块. 思路很简单,有一点细节. 一天内可以不吃巧克力. 注意处理最后时没吃完的全部在最后一天吃完. Code #includ ...
- 洛谷——P2983 [USACO10FEB]购买巧克力Chocolate Buying
P2983 [USACO10FEB]购买巧克力Chocolate Buying 题目描述 Bessie and the herd love chocolate so Farmer John is bu ...
- 洛谷 P2983 [USACO10FEB]购买巧克力Chocolate Buying 题解
P2983 [USACO10FEB]购买巧克力Chocolate Buying 题目描述 Bessie and the herd love chocolate so Farmer John is bu ...
- 洛谷 P2983 [USACO10FEB]购买巧克力Chocolate Buying
购买巧克力Chocolate Buying 乍一看以为是背包,然后交了一个感觉没错的背包上去. #include <iostream> #include <cstdio> #i ...
- P2983 [USACO10FEB]购买巧克力Chocolate Buying
题目描述 Bessie and the herd love chocolate so Farmer John is buying them some. The Bovine Chocolate Sto ...
- 【洛谷】P2983 [USACO10FEB]购买巧克力Chocolate Buying(贪心)
题目描述 Bessie and the herd love chocolate so Farmer John is buying them some. The Bovine Chocolate Sto ...
- 洛谷P2983 [USACO10FEB]购买巧克力Chocolate Buying
题目描述 Bessie and the herd love chocolate so Farmer John is buying them some. The Bovine Chocolate Sto ...
随机推荐
- TeamViewer 软件完全卸载
TeamViewer 软件似乎用于商业环境中 - 彻底卸载 Windows 1. 检测为商业用途该软件似乎用于商业环境中.请注意:免费版仅供个人使用.您的会话将在 5 分钟后终止. 2.1 Close ...
- Spring Cloud学习路线
学习本学习路线学习完,大家将会对微服务.Spring Cloud.Docker.Kubernetes有一个系统.全面的认识.通过学习,将能掌握相关的知识体系,并能够投入到项目实战中去. 本学习路线采用 ...
- Html + JS : 点击对应的按钮,进行选择是隐藏还是显示(用户回复功能)
例如: 当我点击按钮1时,点击第一下进行显示This is comment 01,点击第二下隐藏This is comment 01 当我点击按钮2时,点击第一下进行显示This is comment ...
- 使用ABAP(ADBC)和Java(JDBC)连接SAP HANA数据库
在表DBCON里维护一条记录,指向HANA数据库.con_ENV里填入HANA数据库的主机名和端口号.如vmXXXX:30015 DATA: ls_new TYPE DBCON. ls_new-con ...
- IOS 解析XML数据
● 什么是XML ● 全称是Extensible Markup Language,译作“可扩展标记语言” ● 跟JSON一样,也是常用的一种用于交互的数据格式 ● 一般也叫XML文档(XML ...
- IOS GCD (事例下载图片)
@interface HMViewController () @property (weak, nonatomic) IBOutlet UIImageView *imageView; @end @im ...
- 问题 B: 投简历
题目描述 小华历经12寒窗苦读,又经历4年大学磨砺,终于毕业了,随着毕业季的到来,找工作也日益紧张起来.由于要面试不同的公司,因此小华需要准备不同的简历.当然最基本的信息是必不可少的,基本信息:姓名. ...
- Max answer(The Preliminary Contest for ICPC China Nanchang National Invitational)
Alice has a magic array. She suggests that the value of a interval is equal to the sum of the values ...
- 20145238-荆玉茗 《Java程序设计》第一周学习总结
20145238 <Java程序设计>第一周学习总结 教材学习内容总结 Java三大平台:由于java领域的应用越来越广,根据不同级别的应用开发区分了不同的应用版本,后正式更名为Java ...
- ThinkPHP:create()方法有什么用呢?
1.create方法可以对POST提交的数据进行处理(通过表中的字段名称与表单提交的名称对应关系自动封装数据实例),例如user表中有一个字段名叫"username",如果表单中有 ...