洛谷传送:点传送(中文题面)

[USACO18DEC] The Bucket List

题意:有N头奶牛,每头奶牛产奶开始时间si,结束时间ti,需要桶bi,求最少需要多少只桶能满足所有奶牛需求。

看数据可知道时间最多为1000,所以可以直接按每一刻时间来分析。

思路:枚举每一个时间需要的桶,寻找最大值即为答案。

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int use[1005];//每个时间需要的桶
int main()
{
    int n;
    scanf("%d",&n);
    int i,j,s,t,b;
    for(i=0;i<n;i++)
    {
        scanf("%d%d%d",&s,&t,&b);
        for(j=s;j<t;j++)  //区间时间内需要的桶都要增加
            use[j]+=b;
        use[j]-=b;  //记得还桶
    }
    int maxn=0;    //寻找桶最大值
    for(i=0;i<1002;i++)
    {
        if(use[i]>maxn)
            maxn=use[i];
    }
    printf("%d\n",maxn);
    return 0;
}

 

相关文章:

  • 2021-08-06
  • 2022-02-10
  • 2021-11-22
  • 2021-10-03
  • 2021-07-24
  • 2021-07-23
猜你喜欢
  • 2021-12-05
  • 2021-07-22
  • 2022-12-23
  • 2021-05-30
  • 2022-12-23
  • 2021-06-11
  • 2021-06-26
相关资源
相似解决方案