P3093 [USACO13DEC]牛奶调度Milk Scheduling——贪心

其实可以用dp   f[j]表示到j时间最大的收益

#include<bits/stdc++.h>
using namespace std;
int n,f[100000];
struct node{
int d,g;
}a[1000000];
bool cmp(node a,node b)
{
return a.d<b.d;
}
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i].g>>a[i].d;
}
sort(a+1,a+1+n,cmp);
for(int i=1;i<=n;i++)
{
for(int j=a[i].d;j;j--)//因为要在a[i].d之前
{
f[j]=max(f[j],f[j-1]+a[i].g);
}
}
cout<<*max_element(f+1,f+1+n);
return 0;
}

时间: 2024-12-30 00:01:26

P3093 [USACO13DEC]牛奶调度Milk Scheduling——贪心的相关文章

P3093 [USACO13DEC]牛奶调度Milk Scheduling - 贪心+二叉堆

传送门 思路:一个贪心策略就是"在不挤超过截至时间的奶牛的前提下,尽量挤奶量大的奶牛".So我们将奶牛按截至日期从小到大排序,对于每个截至时间t,将所有截至时间为t的奶牛的奶量加入一个大根堆,只留下前t大的数,剩下的直接删去.由于priority_queue没有clear函数,所以我手写了一个堆...(请不要问我为什么不用小根堆,每次弹出前size()-t个数,但这样做会WA得很惨...) AC Code:(代码略鬼畜,但我觉得应该没多少人看我这博客吧..) #include<c

洛谷P3093 [USACO13DEC]牛奶调度Milk Scheduling

题目描述 Farmer John has N cows that need to be milked (1 <= N <= 10,000), each of which takes only one unit of time to milk. Being impatient animals, some cows will refuse to be milked if Farmer John waits too long to milk them. More specifically, cow

Luogu P1208 [USACO1.3]混合牛奶 Mixing Milk(贪心)

P1208 [USACO1.3]混合牛奶 Mixing Milk 题目描述 由于乳制品产业利润很低,所以降低原材料(牛奶)价格就变得十分重要.帮助Marry乳业找到最优的牛奶采购方案. Marry乳业从一些奶农手中采购牛奶,并且每一位奶农为乳制品加工企业提供的价格是不同的.此外,就像每头奶牛每天只能挤出固定数量的奶,每位奶农每天能提供的牛奶数量是一定的.每天Marry乳业可以从奶农手中采购到小于或者等于奶农最大产量的整数数量的牛奶. 给出Marry乳业每天对牛奶的需求量,还有每位奶农提供的牛奶单

Sicily 13983. Milk Scheduling

13983. Milk Scheduling Constraints Time Limit: 1 secs, Memory Limit: 256 MB Description Farmer John has N cows that need to be milked (1 <= N <= 10,000), each of which takes only one unit of time to milk. Being impatient animals, some cows will refu

洛谷 P1208 [USACO1.3]混合牛奶 Mixing Milk

题目描述 由于乳制品产业利润很低,所以降低原材料(牛奶)价格就变得十分重要.帮助Marry乳业找到最优的牛奶采购方案. Marry乳业从一些奶农手中采购牛奶,并且每一位奶农为乳制品加工企业提供的价格是不同的.此外,就像每头奶牛每天只能挤出固定数量的奶,每位奶农每天能提供的牛奶数量是一定的.每天Marry乳业可以从奶农手中采购到小于或者等于奶农最大产量的整数数量的牛奶. 给出Marry乳业每天对牛奶的需求量,还有每位奶农提供的牛奶单价和产量.计算采购足够数量的牛奶所需的最小花费. 注:每天所有奶农

USACO 1.3 Mixing Milk(贪心)

USACO Mixing Milk 简单的贪心,读入数据,按单价从小到大排序,然后从最便宜的买起,直到买够为止. /* ID:twd30651 PROG:milk LANG:C++ */ #include<iostream> #include<fstream> #include<stdlib.h> using namespace std; int N; int M; typedef struct node { int P; int A; }node; node data

洛谷——P1208 [USACO1.3]混合牛奶 Mixing Milk

https://www.luogu.org/problem/show?pid=1208 题目描述 由于乳制品产业利润很低,所以降低原材料(牛奶)价格就变得十分重要.帮助Marry乳业找到最优的牛奶采购方案. Marry乳业从一些奶农手中采购牛奶,并且每一位奶农为乳制品加工企业提供的价格是不同的.此外,就像每头奶牛每天只能挤出固定数量的奶,每位奶农每天能提供的牛奶数量是一定的.每天Marry乳业可以从奶农手中采购到小于或者等于奶农最大产量的整数数量的牛奶. 给出Marry乳业每天对牛奶的需求量,还

洛谷P2852 [USACO06DEC]牛奶模式Milk Patterns

题目描述 Farmer John has noticed that the quality of milk given by his cows varies from day to day. On further investigation, he discovered that although he can't predict the quality of milk from one day to the next, there are some regular patterns in th

luogu P2949 [USACO09OPEN]工作调度Work Scheduling

题目描述 Farmer John has so very many jobs to do! In order to run the farm efficiently, he must make money on the jobs he does, each one of which takes just one time unit. His work day starts at time 0 and has 1,000,000,000 time units (!). He currently c