洛谷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)\).一个数列的最大贡献定义为其中若干个不相邻的数的和的最大 ...
随机推荐
- html制作简单框架网页二 实现自己的影音驿站 操作步骤及源文件下载 (可播放mp4、avi、mpg、asx、swf各种文件的视频播放代码)
新增视频播放功能如下图: 左侧网页left.html代码如下: <meta charset="utf-8"> <body style="backgrou ...
- InvocationTargetException异常的深入研究-servlet的setAttribute与getAttribute
在某项目中,前端jsp传入的用户id数据通过session域传入后台servlet进行处理的过程中,无意间出现了InvocationTargetException异常 前端部分代码如下:测试代码,非原 ...
- Android(java)学习笔记175:Android进程间通讯(IPC)之AIDL
一.IPC inter process communication 进程间通讯 二.AIDL android interface defination language 安卓接口定义语言 满 ...
- Unity复杂的旋转-欧拉角和四元数
一.欧拉角欧拉角最容易表示,用三个变量X,Y,Z可以直观的表示绕着某个轴的旋转角度. 在Unity里就是Transform组件的Rotation里的X Y Z三个变量代表了欧拉角 二.四元数四元数相比 ...
- 【整理】解决vue不相关组件之间的数据传递----vuex的学习笔记,解决报错this.$store.commit is not a function
解决vue不相关组件之间的数据传递----vuex的学习笔记,解决报错this.$store.commit is not a function https://www.cnblogs.com/jaso ...
- k8s集群部署之环境介绍与etcd数据库集群部署
角色 IP 组件 配置 master-1 192.168.10.11 kube-apiserver kube-controller-manager kube-scheduler etcd 2c 2g ...
- Chrome浏览器安装React developer tools
1. 到 https://github.com/facebook/react-devtools 下载 react-devtools 2. 进入 react-devtools 目录 运行命令 npm ...
- 【传智播客】Libevent学习笔记(二):创建event_base
目录 00. 目录 01. 简介 02. 创建默认的event_base 03. 创建复杂的event_base 3.1 event_config_new函数 3.2 event_base_new_w ...
- Angular JavaScript内存溢出问题 (FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory)
方法一和方法二参考:https://www.cnblogs.com/liugang-vip/p/6857595.html 方法一:my-project/node_modules/.bin 下增大内存( ...
- 树莓派 - 蓝牙 (1) 试试Beacon
首先先了解一下bluez, 以及常用的tools. - hcitool.bluetoothctl等工具,可以进行BLE设备的扫描.连接.配对.广播等操作: - hcitool可以发送HCI comma ...