NC24724 [USACO 2010 Feb S]Chocolate Eating
NC24724 [USACO 2010 Feb S]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.
输入描述
- 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
输出
24
1
1
3
4
5
题解
思路
知识点:二分。
二分睡前快乐,起床后快乐不达标就吃巧克力,达标就不管,中间记得记录吃到第几个巧克力。
坑点:最终答案是要把巧克力在最后一刻全吃完,所以如果达标但是巧克力没吃完,记得都输出在最后一天。
时间复杂度 \(O(D)\)
空间复杂度 \(O(D)\)
代码
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int N, D;
int H[50007];
bool flag;
vector<int> ans(50007);
bool check(ll mid) {
ll h = 0;
int cnt = 0;
for (int i = 0;i < D;i++) {
h >>= 1;
while (h < mid && cnt < N) {
h += H[cnt++];
if (flag) ans[cnt - 1] = i + 1;
}
if (h < mid) return false;
}
return true;
}
int main() {
std::ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> N >> D;
for (int i = 0;i < N;i++) cin >> H[i];
ll l = 0, r = 1e12;
while (l <= r) {
ll mid = l + r >> 1;
if (check(mid)) l = mid + 1;
else r = mid - 1;
}
flag = true;
check(r);
cout << r << '\n';
for (int i = 0;i < N;i++) cout << (ans[i] ? ans[i] : D) << '\n';
return 0;
}
NC24724 [USACO 2010 Feb S]Chocolate Eating的更多相关文章
- BZOJ1782[USACO 2010 Feb Gold 3.Slowing down]——dfs+treap
题目描述 每天Farmer John的N头奶牛(1 <= N <= 100000,编号1…N)从粮仓走向他的自己的牧场.牧场构成了一棵树,粮仓在1号牧场.恰好有N-1条道路直接连接着牧场, ...
- [ USACO 2010 FEB ] Slowing Down
\(\\\) \(Description\) 给出一棵 \(N\) 个点的树和 \(N\) 头牛,每头牛都要去往一个节点,且每头牛去往的点一定互不相同. 现在按顺序让每一头牛去往自己要去的节点,定义一 ...
- USACO翻译:USACO 2012 FEB Silver三题
USACO 2012 FEB SILVER 一.题目概览 中文题目名称 矩形草地 奶牛IDs 搬家 英文题目名称 planting cowids relocate 可执行文件名 planting co ...
- USACO翻译:USACO 2014 FEB SILVER 三题
USACO 2014 FEB SILVER 一.题目概览 中文题目名称 自动打字 路障 神秘代码 英文题目名称 auto rblock scode 可执行文件名 auto rblock scode 输 ...
- BZOJ 2016: [Usaco2010]Chocolate Eating
题目 2016: [Usaco2010]Chocolate Eating Time Limit: 10 Sec Memory Limit: 162 MB Description 贝西从大牛那里收到了 ...
- BZOJ 2016: [Usaco2010]Chocolate Eating( 二分答案 )
因为没注意到long long 就 TLE 了... 二分一下答案就Ok了.. ------------------------------------------------------------ ...
- 2016: [Usaco2010]Chocolate Eating
2016: [Usaco2010]Chocolate Eating Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 224 Solved: 87[Su ...
- [USACO 2018 Feb Gold] Tutorial
Link: USACO 2018 Feb Gold 传送门 A: $dp[i][j][k]$表示前$i$个中有$j$个0且末位为$k$的最优解 状态数$O(n^3)$ #include <bit ...
- P2985 [USACO10FEB]吃巧克力Chocolate Eating
P2985 [USACO10FEB]吃巧克力Chocolate Eating 题目描述 Bessie has received N (1 <= N <= 50,000) chocolate ...
随机推荐
- 机器学习基础:奇异值分解(SVD)
SVD 原理 奇异值分解(Singular Value Decomposition)是线性代数中一种重要的矩阵分解,也是在机器学习领域广泛应用的算法,它不光可以用于降维算法中的特征分解,还可以用于推荐 ...
- Python实现双X轴双Y轴绘图
诈尸人口回归.这一年忙着灌水忙到头都掉了,最近在女朋友的提醒下终于想起来博客的账号密码,正好今天灌水的时候需要画一个双X轴双Y轴的图,研究了两小时终于用Py实现了.找资料的过程中没有发现有系统的文章, ...
- XCTF练习题---MISC---Erik-Baleog-and-Olaf
XCTF练习题---MISC---Erik-Baleog-and-Olaf flag:flag{#justdiffit} 解题步骤: 1.观察题目,下载附件 2.拿到手以后发现是一个没有后缀名的文件, ...
- 论文解读(Debiased)《Debiased Contrastive Learning》
论文信息 论文标题:Debiased Contrastive Learning论文作者:Ching-Yao Chuang, Joshua Robinson, Lin Yen-Chen, Antonio ...
- [Istio是什么?] 还不知道你就out了,一文40分钟快速理解
@ 目录 前言 Istio是什么? 服务网格是什么? 应用场景 为什么使用Istio? 流量管理介绍 istio架构 Envoy Sidecar Istiod 虚拟服务(VirtualService) ...
- 基本命令学习 -(3)Linux压缩和解压缩命令汇总
关注「开源Linux」,选择"设为星标" 回复「学习」,有我为您特别筛选的学习资料~ 前言 Linux下的压缩和解压缩工具比较多,有时经常记不住,这里给大家汇总一下,方便大家查阅. ...
- 详解 Java 17 中新推出的密封类
Java 17推出的新特性Sealed Classes经历了2个Preview版本(JDK 15中的JEP 360.JDK 16中的JEP 397),最终定稿于JDK 17中的JEP 409.Seal ...
- pytorch入门--土堆深度学习快速入门教程
工具函数 dir函数,让我们直到工具箱,以及工具箱中的分隔区有什么东西 help函数,让我们直到每个工具是如何使用的,工具的使用方法 示例:在pycharm的console环境,输入 import t ...
- c++ :STL
基础知识 容器 容器就是一些模板类的集合,不同之处就是容器中封装的是数据结构 1.序列容器 主要有vector向量容器.list列表容器.deque双端队列容器 元素在容器中是无序的 2.排序容器 包 ...
- C# WPF后台动态添加控件(经典)
概述 在Winform中从后台添加控件相对比较容易,但是在WPF中,我们知道界面是通过XAML编写的,如何把后台写好的控件动态添加到前台呢?本节举例介绍这个问题. 这里要用到UniformGrid布局 ...