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. node.js - mysql

    今天结束的挺早,因为今天的内容还可以不是很难,今天全程是学了一些关于mysql数据库和sql查询语句的内容包括在node终端里面怎么来连接数据库.经过今天的一个学习,我感觉离那个地步越来越近了,就是那 ...

  2. 接口测试实战| GET/POST 请求区别详解

    1.请求行的 method 不同:2.POST 可以附加 body,可以支持 form.json.xml.binary等各种数据格式:3.从行业通用规范的角度来说,无状态变化的建议使用 GET 请求, ...

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

    1.简介 上一篇宏哥用PageFactory实现了POM,宏哥再介绍一下如果不用PageFactory如何实现POM. 2.项目实战 在这里宏哥以百度首页登录的例子,如果用POM实现,在测试脚本中实际 ...

  4. 前端 pickerview 的效果 实现 省市区 三级联动

    效果图 需要引入 大佬写的js 以及 css 源文件里面有大佬的地址 这是我存在gitee上的文件 https://gitee.com/depressiom/address-pickview-effe ...

  5. QtWebEngine性能问题

    目录 1. 概述 2. 详论 2.1. 图形属性设置 2.2. 硬件加速设置 2.3. Qt6 3. 参考 1. 概述 Qt的Qt WebEngine模块是基于Chromium项目,但是本人在使用QW ...

  6. 请收藏,Linux 运维必备的 40 个命令总结,收好了~

    点击上方"开源Linux",选择"设为星标" 回复"学习"获取独家整理的学习资料! 1.删除0字节文件 find -type f -size ...

  7. 详解:什么是VXLAN?

    点击上方"开源Linux",选择"设为星标"回复"学习"获取独家整理的学习资料! 本文介绍了什么是VXLAN,以及VXLAN的基本概念和工作 ...

  8. Node.js 中的进程和线程

    线程和进程是计算机操作系统的基础概念,在程序员中属于高频词汇,那如何理解呢?Node.js 中的进程和线程又是怎样的呢? 一.进程和线程 1.1.专业性文字定义 进程(Process),进程是计算机中 ...

  9. 一款高速的NET版的离线免费OCR

    PaddleOCR.Onnx 一款基于Paddle的OCR,项目使用ONNX模型,速度更快.本项目同时支持X64和X86的CPU上使用.本项目是一个基于PaddleOCR的C++代码修改并封装的.NE ...

  10. Elasticsearch高级之-集群搭建,数据分片

    目录 Elasticsearch高级之-集群搭建,数据分片 一 广播方式 二 单播方式 三 选取主节点 四 什么是脑裂 五 错误识别 Elasticsearch高级之-集群搭建,数据分片 es使用两种 ...