题目描述

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 can choose from any of N (1 <= N <= 100,000) jobs

conveniently numbered 1..N for work to do. It is possible but

extremely unlikely that he has time for all N jobs since he can only work on one job during any time unit and the deadlines tend to fall so that he can not perform all the tasks.

Job i has deadline D_i (1 <= D_i <= 1,000,000,000). If he finishes job i by then, he makes a profit of P_i (1 <= P_i <= 1,000,000,000).

What is the maximum total profit that FJ can earn from a given list of jobs and deadlines? The answer might not fit into a 32-bit integer.

约翰有太多的工作要做。为了让农场高效运转,他必须靠他的工作赚钱,每项工作花一个单位时间。 他的工作日从0时刻开始,有1^8个单位时间。在任一时刻,他都可以选择编号1~N的N(1 <= N <= 10^6)项工作中的任意一项工作来完成。 因为他在每个单位时间里只能做一个工作,而每项工作又有一个截止日期,所以他很难有时间完成所有N个工作,虽然还是有可能。 对于第i个工作,有一个截止时间D_i(1 <= D_i <= 10^9),如果他可以完成这个工作,那么他可以获利P_i( 1<=P_i<=10^9 ). 在给定的工作利润和截止时间下,约翰能够获得的利润最大为多少.

输入输出格式

输入格式:

  • Line 1: A single integer: N

  • Lines 2..N+1: Line i+1 contains two space-separated integers: D_i and P_i

输出格式:

  • Line 1: A single number on a line by itself that is the maximum possible profit FJ can earn.

输入输出样例

输入样例#1:

  1. 3
  2. 2 10
  3. 1 5
  4. 1 7
输出样例#1:

  1. 17

说明

Complete job 3 (1,7) at time 1 and complete job 1 (2,10) at time 2 to maximize the earnings (7 + 10 -> 17).

思路:用一个优先对列进行贪心。

错因:优先队列的优先级是先大后小,我以为是先小后大。

  1. #include<queue>
  2. #include<cstdio>
  3. #include<cstring>
  4. #include<iostream>
  5. #include<algorithm>
  6. using namespace std;
  7. int n;
  8. long long ans,time;
  9. struct nond{
  10. long long end,val;
  11. }v[];
  12. priority_queue<long long,vector<long long>,greater<long long> >que;
  13. int cmp(nond a,nond b){
  14. return a.end<b.end;
  15. }
  16. int main(){
  17. cin>>n;
  18. for(int i=;i<=n;i++)
  19. cin>>v[i].end>>v[i].val;
  20. sort(v+,v++n,cmp);
  21. for(int i=;i<=n;i++){
  22. if(time<v[i].end){
  23. time++;
  24. ans+=v[i].val;
  25. que.push(v[i].val);
  26. }
  27. else if(time==v[i].end&&que.top()<v[i].val){
  28. ans-=que.top();
  29. ans+=v[i].val;
  30. que.pop();
  31. que.push(v[i].val);
  32. }
  33. }
  34. cout<<ans;
  35. }

洛谷 P2949 [USACO09OPEN]工作调度Work Scheduling的更多相关文章

  1. 洛谷 P2949 [USACO09OPEN]工作调度Work Scheduling 题解

    P2949 [USACO09OPEN]工作调度Work Scheduling 题目描述 Farmer John has so very many jobs to do! In order to run ...

  2. luogu P2949 [USACO09OPEN]工作调度Work Scheduling

    题目描述 Farmer John has so very many jobs to do! In order to run the farm efficiently, he must make mon ...

  3. P2949 [USACO09OPEN]工作调度Work Scheduling

    题目描述 约翰有太多的工作要做.为了让农场高效运转,他必须靠他的工作赚钱,每项工作花一个单位时间. 他的工作日从0时刻开始,有10^8个单位时间.在任一时刻,他都可以选择编号1~N的N(1 <= ...

  4. LUOGU P2949 [USACO09OPEN]工作调度Work Scheduling (贪心)

    解题思路 明明一道比较简单的贪心结果挂了好几次23333,就是按照时间排序,然后拿一个小根堆维护放进去的,如果时间允许就入队并且记录答案.如果不允许就从堆里拿一个最小的比较. #include< ...

  5. 题解 P2949 【[USACO09OPEN]工作调度Work Scheduling】

    P2949 [USACO09OPEN]工作调度Work Scheduling 题目标签是单调队列+dp,萌新太弱不会 明显的一道贪心题,考虑排序先做截止时间早的,但我们发现后面可能会出现价值更高却没有 ...

  6. [USACO09OPEN] 工作调度Work Scheduling (贪心/堆)

    [USACO09OPEN] 工作调度Work Scheduling 题意翻译 约翰有太多的工作要做.为了让农场高效运转,他必须靠他的工作赚钱,每项工作花一个单位时间. 他的工作日从0时刻开始,有10^ ...

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

    题目描述 Farmer John has N cows that need to be milked (1 <= N <= 10,000), each of which takes onl ...

  8. [luoguP2949] [USACO09OPEN]工作调度Work Scheduling(贪心 + 优先队列)

    传送门 这个题类似于建筑抢修. 先按照时间排序. 如果当前时间小于任务截止时间就选, 否则,看看当前任务价值是否比已选的任务的最小价值大, 如果是,就替换. 可以用优先队列. ——代码 #includ ...

  9. 洛谷 2953 [USACO09OPEN]牛的数字游戏Cow Digit Game

    洛谷 2953 [USACO09OPEN]牛的数字游戏Cow Digit Game 题目描述 Bessie is playing a number game against Farmer John, ...

随机推荐

  1. [jQuery]ajax同步请求在方法内问题

    在函数内写$.ajax() 的成功函数中return 的值,并没有return到外层方法返回至

  2. ASP.Net Cookie总结

    Cookie是一段文本信息,在客户端存储 Cookie 是 ASP.NET 的会话状态将请求与会话关联的方法之一.Cookie 也可以直接用于在请求之间保持数据,但数据随后将存储在客户端并随每个请求一 ...

  3. unix关于打包命令zip的使用

    unix zip命令的基本使用方法是: zip [參数] [打包后的文件名称] [打包的文件夹路径] linux zip命令參数列表: -a 将文件转成ASCII模式 -F 尝试修复损坏的压缩文件 - ...

  4. OpenStack Heat总结之:Icehouse中通过Heat+Ceilometer实现Autoscaling

    在I版本号中,Heat中加入了对于AutoScaling资源的支持.github上也提供了相应的AutoScaling的模板(https://github.com/openstack/heat-tem ...

  5. 上机题目(中级)- 两个超级大的整数相加相减 (Java)

    代码例如以下: public class AddSub { public static void main(String[] args) { String a="46328648326846 ...

  6. 2016 提高组c++ 错题

    需重做 树的重心 链表 计算机基础知识 无线通讯技术: 蓝牙,wifi,GPRS 现在常用的无线通信技术:FM调频广播(用于收音机): 2G.3G移动通信技术(中国移动.中国联通.中国电信正在运营的网 ...

  7. 34.QT模型(表格绘制)

    modellex.h #ifndef MODELEX_H #define MODELEX_H #include <QAbstractItemModel> #include <QVec ...

  8. 调试相关blogs收集

    Debug Diag官方blog  https://blogs.msdn.microsoft.com/debugdiag/ Tess  https://blogs.msdn.microsoft.com ...

  9. SQL Server 内存使用情况

    • 查看设置的最大与最小内存: exec sp_configure 'max server memory (MB)' exec sp_configure 'min server memory (MB) ...

  10. vue中采用axios发送请求及拦截器

    这几天在使用vue中axios发送get请求的时候很顺手,但是在发送post请求的时候老是在成功的回调函数里边返回参数不存在,当时就纳闷了,经过查阅资料,终于得到了解决方案,在此做一总结: 首先我们在 ...