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的更多相关文章

  1. BZOJ1782[USACO 2010 Feb Gold 3.Slowing down]——dfs+treap

    题目描述 每天Farmer John的N头奶牛(1 <= N <= 100000,编号1…N)从粮仓走向他的自己的牧场.牧场构成了一棵树,粮仓在1号牧场.恰好有N-1条道路直接连接着牧场, ...

  2. [ USACO 2010 FEB ] Slowing Down

    \(\\\) \(Description\) 给出一棵 \(N\) 个点的树和 \(N\) 头牛,每头牛都要去往一个节点,且每头牛去往的点一定互不相同. 现在按顺序让每一头牛去往自己要去的节点,定义一 ...

  3. USACO翻译:USACO 2012 FEB Silver三题

    USACO 2012 FEB SILVER 一.题目概览 中文题目名称 矩形草地 奶牛IDs 搬家 英文题目名称 planting cowids relocate 可执行文件名 planting co ...

  4. USACO翻译:USACO 2014 FEB SILVER 三题

    USACO 2014 FEB SILVER 一.题目概览 中文题目名称 自动打字 路障 神秘代码 英文题目名称 auto rblock scode 可执行文件名 auto rblock scode 输 ...

  5. BZOJ 2016: [Usaco2010]Chocolate Eating

    题目 2016: [Usaco2010]Chocolate Eating Time Limit: 10 Sec  Memory Limit: 162 MB Description 贝西从大牛那里收到了 ...

  6. BZOJ 2016: [Usaco2010]Chocolate Eating( 二分答案 )

    因为没注意到long long 就 TLE 了... 二分一下答案就Ok了.. ------------------------------------------------------------ ...

  7. 2016: [Usaco2010]Chocolate Eating

    2016: [Usaco2010]Chocolate Eating Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 224  Solved: 87[Su ...

  8. [USACO 2018 Feb Gold] Tutorial

    Link: USACO 2018 Feb Gold 传送门 A: $dp[i][j][k]$表示前$i$个中有$j$个0且末位为$k$的最优解 状态数$O(n^3)$ #include <bit ...

  9. P2985 [USACO10FEB]吃巧克力Chocolate Eating

    P2985 [USACO10FEB]吃巧克力Chocolate Eating 题目描述 Bessie has received N (1 <= N <= 50,000) chocolate ...

随机推荐

  1. React项目中使用wangeditor以及扩展上传附件菜单

    在最近的工作中需要用到富文本编辑器,结合项目的UI样式以及业务需求,选择了wangEditor.另外在使用的过程中发现wangEditor只有上传图片和视频的功能,没有上传文本附件的功能,所以需要对其 ...

  2. Confluent之Kafka Connector初体验

    概述 背景 Apache Kafka 是最大.最成功的开源项目之一,可以说是无人不知无人不晓,在前面的文章<Apache Kafka分布式流处理平台及大厂面试宝典>我们也充分认识了Kafk ...

  3. 手把手教会将 Windows 窗体桌面应用从.NET Framework迁移到 .NET SDK/.NET 6 格式

    接上篇:手把手教会 VS2022 设计 Winform 高DPI兼容程序 (net461 net6.0 双出) https://www.cnblogs.com/densen2014/p/1614293 ...

  4. 基于深度学习的人脸性别识别系统(含UI界面,Python代码)

    摘要:人脸性别识别是人脸识别领域的一个热门方向,本文详细介绍基于深度学习的人脸性别识别系统,在介绍算法原理的同时,给出Python的实现代码以及PyQt的UI界面.在界面中可以选择人脸图片.视频进行检 ...

  5. 《手把手教你》系列基础篇(九十三)-java+ selenium自动化测试-框架设计基础-POM设计模式实现-上篇(详解教程)

    1.简介 上一篇介绍了POM的基础理论知识和非POM方式写脚本,这篇介绍利用页面工厂类(page factory)去实现POM,通过查看PageFactory类,我们可以知道它是一个初始化一个页面实例 ...

  6. 3.1 常用Linux命令

    1.echo命令 echo命令用于在终端设备上输出字符串或变量提取后的值,语法格式为"echo [字符串] [$变量]". 2.date命令 date命令用于显示或设置系统的时间与 ...

  7. zookeeper篇-初识zookeeper

    点赞再看,养成习惯,微信搜索「小大白日志」关注这个搬砖人. 文章不定期同步公众号,还有各种一线大厂面试原题.我的学习系列笔记. 什么是zookeeper? 中间件 作用于分布式系统 支持java.c语 ...

  8. input输入框自动填充的问题

    火狐浏览器打开页面,input可以自动填充历史输入值,现在想无论input类型是type='text'还是'password'都禁止自动填充,因为我写的页面在input='text'时先检查是否有输入 ...

  9. Oracle 数据库表删除重复数据

    删除重复数据并保留一条 方法一 1.建立临时表,记录重复的数据 create table 临时表 as select a.字段1,a.字段2,max(a.rowid) as dataid from 原 ...

  10. 1.17 想学好Linux,这些习惯必须养成(初学者必读)

    不管是在生活还是工作中,每个人都会逐渐养成一些小习惯.坏习惯一旦形成就很难改正,所在在系统学习 Linux之前,给大家一些建议,刻意去培养一些好的习惯,对自己是很有利的. 学习Linux,要习惯使用命 ...