Codeforces 460C Present

本文探讨了一种策略,通过合理安排浇水时间,最大化在m天后花园中最低花高的值。利用二分查找算法在特定范围内确定浇水的最佳方案。

题目链接:


题意:有n朵花,有m天,每一天可以对第i朵花浇水,会影响到[i,i+w-1]区间里的花,使他们长高1长度,求m天后所有花里最矮的花的高度最大值(写的好绕口啊……)


思路:因为求得是所有花里最矮的最大值……所以区间一定在[min,max+m]里所以用二分就可以了,然后对每一朵高度不够的花进行浇水操作,利用hei数组记录停止影响的花朵,变量day记录浇水的天数


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define maxn 100030
#define inf 0x3f3f3f3f
using namespace std;

int s[maxn],hei[maxn];
int n,m,w;


int jde(int gold)
{
   memset(hei,0,sizeof(hei));
   int day=0,kot=m;
   for (int i=0;i<n;i++)
   {
       day+=hei[i];
       if (s[i]+day<gold)
       {
           int tem=gold-s[i]-day;
           if (i+w<n)hei[i+w]-=tem;
           kot-=tem;
           day+=tem;
           if (kot<0) return 0;
       }


   }
    return 1;
}

int main()
{

    while (scanf("%d%d%d",&n,&m,&w)!=EOF)
    {
        int r=-inf,l=inf,res;
        for (int i=0;i<n;i++)
        {
            scanf("%d",&s[i]);
            r=max(r,s[i]);
            l=min(l,s[i]);
        }
        r+=m;
        res=l;
        while (l<=r)
        {
            int mid=(r+l)>>1;
            if (jde(mid))
            {
               l=mid+1;
               res=max(mid,res);
            }
            else
            {
                r=mid-1;
            }

        }
        printf("%d\n",res);
    }

}




### Codeforces Problem 1332C Explanation The provided references pertain specifically to problem 742B on Codeforces rather than problem 1332C. For an accurate understanding and solution approach for problem 1332C, it's essential to refer directly to its description and constraints. However, based on general knowledge regarding competitive programming problems found on platforms like Codeforces: Problem 1332C typically involves algorithmic challenges that require efficient data structures or algorithms such as dynamic programming, graph theory, greedy algorithms, etc., depending upon the specific nature of the task described within this particular question[^6]. To provide a detailed explanation or demonstration concerning **Codeforces problem 1332C**, one would need direct access to the exact statement associated with this challenge since different tasks demand tailored strategies addressing their unique requirements. For obtaining precise details about problem 1332C including any sample inputs/outputs along with explanations or solutions, visiting the official Codeforces website and navigating to contest number 1332 followed by examining section C is recommended. ```python # Example pseudo-code structure often seen in solving competitive coding questions. def solve_problem_1332C(input_data): # Placeholder function body; actual logic depends heavily on the specifics of problem 1332C. processed_result = process_input(input_data) final_answer = compute_solution(processed_result) return final_answer input_example = "Example Input" print(solve_problem_1332C(input_example)) ```
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值