洛谷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)\).一个数列的最大贡献定义为其中若干个不相邻的数的和的最大 ...
随机推荐
- C#实现为类和函数代码自动添加版权注释信息的方法
这篇文章主要介绍了C#实现为类和函数代码自动添加版权注释信息的方法,主要涉及安装文件的修改及函数注释模板的修改,需要的朋友可以参考下 本文实例讲述了C#实现为类和函数代码自动添加版权注释信息的方法 ...
- AJPFX简述Scanner类的特点
hasNextInt() :判断是否还有下一个输入项,其中Xxx可以是Int,Double等.如果需要判断是否包含下一个字符串,则可以省略Xxx nextInt(): 获取下一个输入项. ...
- 【学习笔记】深入理解js原型和闭包(6)——继承
为何用“继承”为标题,而不用“原型链”? 原型链如果解释清楚了很容易理解,不会与常用的java/C#产生混淆.而“继承”确实常用面向对象语言中最基本的概念,但是java中的继承与javascript中 ...
- iOS 根据屏幕宽度, 高度判断手机设备
#define iPhone_5 [UIScreen mainScreen].bounds.size.width == 320.0 #define iPhone_6 [UIScreen mainScr ...
- Winform用Post方式打开IE
1.主要实现Code void OpenNewIe(string url, string postData)///url是要post的网址,postData是要传入的参数 { if (ie != nu ...
- resharper10 注册方法
注册工具:http://pan.baidu.com/s/1bnFjGfX 注册方法: 1 编辑Products.json文件,留下自己要注册的产品路径即可. 2 运行patch.exe 3 使用Ser ...
- vue >>> 编译失败问题 loader 待解决( iview vue脚手架生成)
vue >>> 编译失败问题 loader 待解决 用vue iview 脚手架 来一次试试~
- unnamed not found for the web module
intellij idea tomcat 启动报错not found for the web module 使用intellij idea 创建tomcat项目的时候会出现该错误: 启动tomcat的 ...
- PHP06 流程控制
学习要点 选择结构 循环结构 学习目标 掌握PHP的选择结构 掌握PHP的循环结构 流程控制概述 程序 程序:一系列计算机指令的集合. 编程语言:开发程序的工具. 程序执行结构 计算机程序有三种基本执 ...
- [SNOI2019]数论
题目 考虑对于每一个\(a_i\)计算有多少个\(0<x\leq T-1\)满足\(x\equiv a_i(mod\ P)\)且\(x\ mod\ Q \in B\) 显然\(x=a_i+k\t ...