洛谷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 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.
输入输出样例
4
10 3
7 5
8 1
2 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.
倒序循环时间,把最后期限晚于当前时间的加入堆,贪心每次取一个最大值。
/*by SilverN*/
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<queue>
using namespace std;
const int mxn=;
int read(){
int x=,f=;char ch=getchar();
while(ch<'' || ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>='' && ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int n;
struct node{
int d,g;
}a[mxn];
int cmp(const node a,const node b){
return a.d>b.d;
}
priority_queue<int>tp;
int main(){
n=read();
int i,j;
for(i=;i<=n;i++){
a[i].g=read();
a[i].d=read();
}
sort(a+,a+n+,cmp);
int hd=;
int ans=;
for(i=a[].d;i;--i){
while(a[hd].d>=i){
tp.push(a[hd].g);
hd++;
}
if(tp.empty())continue;
ans+=tp.top();
tp.pop();
}
cout<<ans<<endl;
return ;
}
洛谷P3093 [USACO13DEC]牛奶调度Milk Scheduling的更多相关文章
- [USACO13DEC]牛奶调度Milk Scheduling
原题链接https://www.lydsy.com/JudgeOnline/problem.php?id=4096 容易想到的一个测略就是,优先考虑结束时间小的牛.所以我们对所有牛按照结束时间排序.然 ...
- [洛谷P2852] [USACO06DEC]牛奶模式Milk Patterns
洛谷题目链接:[USACO06DEC]牛奶模式Milk Patterns 题目描述 Farmer John has noticed that the quality of milk given by ...
- 洛谷 P2949 [USACO09OPEN]工作调度Work Scheduling 题解
P2949 [USACO09OPEN]工作调度Work Scheduling 题目描述 Farmer John has so very many jobs to do! In order to run ...
- 洛谷 P2949 [USACO09OPEN]工作调度Work Scheduling
P2949 [USACO09OPEN]工作调度Work Scheduling 题目描述 Farmer John has so very many jobs to do! In order to run ...
- P3074 [USACO13FEB]牛奶调度Milk Scheduling
题目描述 Farmer John's N cows (1 <= N <= 10,000) are conveniently numbered 1..N. Each cow i takes ...
- 洛谷P3063 [USACO12DEC]牛奶的路由Milk Routing
链接 其实在博客园里写题解都挺应付的都是在洛谷写了之后 挑一部分粘过来 在洛谷写的也都是废话,是为了凑篇幅 主要就是代码 大体思路就一提 这题贪心不行废话 跑m遍SPFA更新最小值 注意数组记得清空 ...
- 洛谷 P3063 [USACO12DEC]牛奶的路由Milk Routing
P3063 [USACO12DEC]牛奶的路由Milk Routing 题目背景 征求翻译.如果你能提供翻译或者题意简述,请直接发讨论,感谢你的贡献. 题目描述 Farmer John's farm ...
- 洛谷 P1208混合牛奶【贪心】
题目描述 由于乳制品产业利润很低,所以降低原材料(牛奶)价格就变得十分重要.帮助Marry乳业找到最优的牛奶采购方案. Marry乳业从一些奶农手中采购牛奶,并且每一位奶农为乳制品加工企业提供的价格是 ...
- 洛谷P3097 - [USACO13DEC]最优挤奶Optimal Milking
Portal Description 给出一个\(n(n\leq4\times10^4)\)个数的数列\(\{a_n\}(a_i\geq1)\).一个数列的最大贡献定义为其中若干个不相邻的数的和的最大 ...
随机推荐
- spring mvc支持跨域请求
@WebFilter(urlPatterns = "/*", filterName = "corsFilter") public class CorsFilte ...
- 前端之CSS语法及选择器
一.css语法: css由两大部分组成:选择符和声明,声明由属性和属性值两部分组成; 选择符{属性:属性值;属性:属性值;} 注: a) 属性和属性值之间用冒号连接: b)每条声明结束要加分号: 二. ...
- BaseAtapter
本文用于实现一个通用的BaseAdapter类,统一产品的Adapter类,作为一个工具类,减少重复性工作,增加开发效率. 序 我们在开发项目的过程中,经常会用到ListView.GridView这一 ...
- 一个Java编写的小玩意儿--脚本语言解释器(一)
今天开始想写一个脚本语言编译器.在这个领域,我还是知道的太少了,写的这个过程肯定是艰辛的,因为之前从来没有接触过这类的东西.写在自己的博客里,算是记录自己的学习历程吧.相信将来自己有幸再回过头来看到自 ...
- Linux PHP的运行模式
关系图 首先聊一下服务器,常见的web server类型有apache和nginx Apache工作模式 Apache的工作模式是Apache服务器在系统启动后,预先生成多个进程副本驻留在内存中,一旦 ...
- C#创建任务计划
因写的调用DiskPart程序是要用管理员身份运行的,这样每次开机检查都弹个框出来确认肯定不行.搜了下,似乎也只是使用任务计划程序运行来绕过UAC提升权限比较靠谱,网上的都是添加到计算机启动的,不是指 ...
- 求N个数的最大公约数
使用 “辗转相除法” 计算2个数的最大公因数: int GCD_2(int nNum1, int nNum2) { if (nNum1 > nNum2) { nNum1 = nNum1 ^ nN ...
- codevs 2600 13号星期几?
时间限制: 1 s 空间限制: 8000 KB 题目等级 : 黄金 Gold 题目描述 Description 从1900年1月1日(星期一) 开始经过的n年当中,每个月的13号这一天是星期一.星 ...
- HashMap详解 基于jdk1.7
转载自:http://zhangshixi.iteye.com/blog/672697 1. HashMap概述: HashMap是基于哈希表的Map接口的非同步实现.此实现提供所有可选的映射操 ...
- uva1336 Fixing the Great Wall
用到了kase避免memset超时 #include<cstdio> #include<cstring> #include<cmath> #include<a ...