luogu P2985 [USACO10FEB]吃巧克力Chocolate Eating

题目描述

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

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int mod=10007,N=5e4+10;
#define int long long
int n,m,h[N],a[N];
inline bool check(int x){
    int op=0,j=0;
    for(int i=1;i<=m;i++){
        op=op>>1;
        while(op<x&&j<n){j++;op+=h[j];a[j]=i;}
        if(op<x)return 0;
    }
    return 1;
}
signed main(){
    cin>>n>>m;
    int l=0,r=10,ans=-1;
    for(int i=1;i<=n;i++)
    scanf("%lld",&h[i]),r+=h[i];
    while(l<=r){
        int mid=(l+r)>>1;
        if(check(mid)){
            l=mid+1;
            ans=mid;
        }else r=mid-1;
    }
    cout<<ans<<endl;
    memset(a,0,sizeof(a));
    check(ans);
    for(int i=1;i<=n;i++)
    if(a[i])printf("%lld\n",a[i]);
    else printf("%lld\n",m);
}

原文地址:https://www.cnblogs.com/naruto-mzx/p/11781239.html

时间: 2024-11-10 00:19:16

luogu P2985 [USACO10FEB]吃巧克力Chocolate Eating的相关文章

[USACO10FEB]吃巧克力Chocolate Eating

题目:洛谷P2985. 题目大意:有n块巧克力要吃d天,并且只能按顺序吃.一块巧克力有一个开心值,吃了就能增加开心值.一个人初始开心值为0,且每天早上开心值变为原来的一半.问如何吃巧克力才能使开心值最小的一天开心值最大(每天都按吃完巧克力后计算),且需要输出方案. 解题思路:最大化最小值问题,用二分答案. 贪心地扫描,对于一个答案,如果开心值不到这个答案,就一直吃巧克力即可. 最后输出吃的方案时也用此种贪心法. 注意如果最后巧克力没有吃完,则在最后一天全部吃掉. C++ Code: #inclu

【luogu P2984 [USACO10FEB]给巧克力Chocolate Giving】 题解

题目链接:https://www.luogu.org/problemnew/show/P2984 练习SPFA,把FJ当做起点,求出到所有牛的最短路,再把两个牛的相加. 1 #include <cstdio> 2 #include <queue> 3 #include <iostream> 4 #include <algorithm> 5 #include <cstring> 6 using namespace std; 7 const int

洛谷—— P2983 [USACO10FEB]购买巧克力Chocolate Buying

https://www.luogu.org/problem/show?pid=2983 题目描述 Bessie and the herd love chocolate so Farmer John is buying them some. The Bovine Chocolate Store features N (1 <= N <= 100,000) kinds of chocolate in essentially unlimited quantities. Each type i of

洛谷——P2984 [USACO10FEB]给巧克力Chocolate Giving

https://www.luogu.org/problem/show?pid=2984 题目描述 Farmer John is distributing chocolates at the barn for Valentine's day, and B (1 <= B <= 25,000) of his bulls have a special cow in mind to receive a chocolate gift. Each of the bulls and cows is graz

洛谷P2983 [USACO10FEB]购买巧克力Chocolate Buying

题目描述 Bessie and the herd love chocolate so Farmer John is buying them some. The Bovine Chocolate Store features N (1 <= N <= 100,000) kinds of chocolate in essentially unlimited quantities. Each type i of chocolate has price P_i (1 <= P_i <= 1

洛谷 P2984 [USACO10FEB]给巧克力Chocolate Giving

题目描述 Farmer John is distributing chocolates at the barn for Valentine's day, and B (1 <= B <= 25,000) of his bulls have a special cow in mind to receive a chocolate gift. Each of the bulls and cows is grazing alone in one of the farm's N (2*B <=

BZOJ 2016: [Usaco2010]Chocolate Eating

题目 2016: [Usaco2010]Chocolate Eating Time Limit: 10 Sec  Memory Limit: 162 MB Description 贝西从大牛那里收到了N块巧克力.她不想把它们马上吃完,而是打算制定一个计划, 使得在接下来的D天里,她能够尽量地快乐.贝西的快乐指数可以用一个整数来衡量,一开始的时候是0,当她每天晚上睡觉的时候,快乐指数会减半(奇数时向下取整).贝西把她的巧克力按照收到的时间排序,并坚持按照这个顺序来吃巧克力.当她吃掉第i块巧克力的时

bzoj2016[Usaco2010]Chocolate Eating

bzoj2016[Usaco2010]Chocolate Eating 题意: n块巧克力,每次吃可以增加ai点快乐,每天早晨睡觉起来快乐值会减半,求如何使d天睡觉前的最小快乐值最大.n,d≤50000 题解: 二分快乐值,每天不够就吃.注意如果最后一天有剩余巧克力,必须将其全部吃完. 代码: 1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 #define ll long long 5

2016: [Usaco2010]Chocolate Eating

2016: [Usaco2010]Chocolate Eating Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 224  Solved: 87[Submit][Status][Discuss] Description 贝西从大牛那里收到了N块巧克力.她不想把它们马上吃完,而是打算制定一个计划, 使得在接下来的D天里,她能够尽量地快乐.贝西的快乐指数可以用一个整数来衡量,一开始的时候是0,当她每天晚上睡觉的时候,快乐指数会减半(奇数时向下取整).