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 ...
随机推荐
- selenium找不到元素
1.页面元素处于不显示状态时,找不元素.必须使元素处于显示状态.使用js 或者 元素的点击事件等方式可以实现. " src="index.php?m=Index&a=Men ...
- 搭建Web开发环境JavaEE_Eclipse
1. 下载和安装1.1 下载JDK在Java官方网站下载最新版本的 Java SE: http://www.oracle.com/technetwork/java/javase/downloads/ ...
- 初学React:JSX语法
这是本人初学React做的学习笔记;讲的不是很深,只算是简单的进行介绍. 这是一个小系列.都是在同一个模板中搭建的,但是代码是不能正常执行的. >>第一个组件.js 'use strick ...
- Ruby SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B:
最近使用ruby-china的源连接不上 使用gem update遇到这个问题, 原来是ruby没有包含SSL证书,所以Https的链接被服务器拒绝. 解决方法很简单,首先在这里下载证书(http:/ ...
- 1.10 从表中随机返回n条记录
同时使用内置函数的rand函数. limit 和order by: select * from emp order by rand() limit 2;
- POJ-2376 Cleaning Shifts---区间覆盖&贪心
题目链接: https://vjudge.net/problem/POJ-2376 题目大意: farmer John要安排他的牛清理牛棚,一共有T个牛棚要清理,每头牛可以清理相邻的牛棚.比如,一头牛 ...
- Codeforces Round #347 (Div.2)_B. Rebus
题目链接:http://codeforces.com/contest/664/problem/B B. Rebus time limit per test 1 second memory limit ...
- Angular2入门--架构概览
Angular 介绍 Angular 是一款来自谷歌的开源的web前端框架,诞生于2009年,是一款优秀的前端JS框架,已经被用于谷歌的多款产品. Angular 基于Typescript开发 ,更适 ...
- Spring boot 实现高吞吐量异步处理(适用于高并发场景)
技术要点 org.springframework.web.context.request.async.DeferredResult<T> 示例如下: 1. 新建Maven项目 asy ...
- 11、SpringBoot------定时任务
开发工具:STS 代码下载链接:https://github.com/theIndoorTrain/Springboot/tree/52ef6c0c805913db1e66ed18671c322e ...