洛谷 P3093 [USACO13DEC]牛奶调度Milk Scheduling
来源:互联网 发布:张韶涵 知乎 编辑:程序博客网 时间:2024/05/18 15:06
题目描述
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 i produces g_i gallons of milk (1 <= g_i <= 1000), but only if she is milked before a deadline at time d_i (1 <= d_i <= 10,000). Time starts at t=0, so at most x total cows can be milked prior to a deadline at time t=x.
Please help Farmer John determine the maximum amount of milk that he can obtain if he milks the cows optimally.
FJ有N(1 <= N <= 10,000)头牛要挤牛奶,每头牛需要花费1单位时间。
奶牛很厌烦等待,奶牛i在它的截止时间d_i (1 <= d_i <= 10,000)前挤g(1 <= g_i <= 1000)的奶,否则将不能挤奶。时间t开始时为0,即在时间t=x时,最多可以挤x头奶牛。
请计算FJ的最大挤奶量。
输入输出格式
输入格式:
Line 1: The value of N.Lines 2..1+N: Line i+1 contains the integers g_i and d_i.
输出格式:
Line 1: The maximum number of gallons of milk Farmer John can obtain.
输入输出样例
输入样例#1:
4
10 3
7 5
8 1
2 1
输出样例#1:
25
说明
There are 4 cows. The first produces 10 gallons of milk if milked by time 3, and so on.
Farmer John milks cow 3 first, giving up on cow 4 since she cannot be milked by her deadline due to the conflict with cow 3. Farmer John then milks cows 1 and 2.
考虑贪心地选取,先选产奶量最大的,在截止日期挤,剩下的截止日期不能挤,就向前推。
#include<algorithm>#include<iostream>#include<cstdio>using namespace std;const int N=1e4+5;int n,ans;bool b[10004];struct cow{ int dt,mlk;}a[N];bool cmp(cow c,cow d){ return c.mlk>d.mlk;}int main(){ scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d%d",&a[i].mlk,&a[i].dt); sort(a+1,a+n+1,cmp); for(int i=1;i<=n;i++) for(int j=a[i].dt;j>=1;j--) if(!b[j]) { ans+=a[i].mlk; b[j]=1; break; } printf("%d\n",ans); return 0;}
- 洛谷 P3093 [USACO13DEC]牛奶调度Milk Scheduling
- P3093 [USACO13DEC]牛奶调度Milk Scheduling
- 洛谷P3093 [USACO13DEC]牛奶调度Milk Scheduling(贪心)
- 洛谷 P3093 牛奶调度Milk Scheduling
- 洛谷 3093 [USACO13DEC]牛奶调度Milk Scheduling
- 【洛谷 3093】[USACO13DEC]牛奶调度Milk Scheduling
- 【USACO13DEC】洛谷3093 Milk Scheduling
- Mixing Milk混合牛奶
- 牛奶模式Milk Patterns
- SOJ 12261 Milk Scheduling
- Sicily 13983. Milk Scheduling
- |洛谷|贪心|P1208 [USACO1.3]混合牛奶 Mixing Milk
- 洛谷1208[USACO1.3]混合牛奶 Mixing Milk
- 洛谷 P1208 USACO 1.3 混合牛奶 Mixing Milk
- 洛谷 P1208 [USACO1.3]混合牛奶 Mixing Milk
- 洛谷 2P1208 [USACO1.3]混合牛奶 Mixing Milk
- 洛谷P1208 [USACO1.3]混合牛奶 Mixing Milk
- 【寒假任务】 洛谷1208 [USACO1.3]混合牛奶 Mixing Milk
- ubuntu键盘映射
- hdu5925 离散化+bfs
- TankWar 单机(JAVA版) 版本1.5 画一辆敌方的坦克
- 求最值
- mysql登录错误Plugin '*F7BDD2C0FCF95E6591A14EBCE522D8B16C8EE2F6' is not loaded
- 洛谷 P3093 [USACO13DEC]牛奶调度Milk Scheduling
- 日本人为何能拿这么多诺贝尔奖
- 高可用性测试
- 计算机算法设计与分析之不定期更新的日常+动态规划矩阵连乘+最长公共子序列
- C# 指针之美
- Failure [DELETE_FAILED_INTERNAL_ERROR] 不能卸载
- Android最好用、最强大的图片加载框架:Fresco的简单实用教程
- HDU 1198 Farm Irrigation
- Best Cow Line(POJ 3617) 贪心