题目描述

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:

3
2 10
1 5
1 7
输出样例#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).

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

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

#include<queue>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int n;
long long ans,time;
struct nond{
long long end,val;
}v[];
priority_queue<long long,vector<long long>,greater<long long> >que;
int cmp(nond a,nond b){
return a.end<b.end;
}
int main(){
cin>>n;
for(int i=;i<=n;i++)
cin>>v[i].end>>v[i].val;
sort(v+,v++n,cmp);
for(int i=;i<=n;i++){
if(time<v[i].end){
time++;
ans+=v[i].val;
que.push(v[i].val);
}
else if(time==v[i].end&&que.top()<v[i].val){
ans-=que.top();
ans+=v[i].val;
que.pop();
que.push(v[i].val);
}
}
cout<<ans;
}

洛谷 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. Elasticsearch Sliced Scroll分页检索案例分享

    面试:你懂什么是分布式系统吗?Redis分布式锁都不会?>>>   The best elasticsearch highlevel java rest api-----bboss ...

  2. HDU 5372 Segment Game

    /** 多校联合2015-muti7-1004 <a target=_blank href="http://acm.hdu.edu.cn/showproblem.php?pid=537 ...

  3. 杭电1018-Big Number(大数)

    Big Number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total ...

  4. Error: CompareBaseObjectsInternal can only be called from the main thread

    Posted: 01:39 PM 06-17-2013 hi, we're working on a project where we need to do some calculations on ...

  5. fgets()函数和sscanf()函数的使用方法

    fgets 百度百科:从文件结构体指针stream中读取数据,每次读取一行.读取的数据保存在buf指向的字符数组中.每次最多读取bufsize-1个字符(第bufsize个字符赋'\0'),假设文件里 ...

  6. c2

    #include <stdio.h> int main() { // 整型常量 ; // 实型常量(小数) // 单精度float / 双精度double // 注意: 默认情况下编写的小 ...

  7. java old GC和young GC

    Java内存分配机制 摘自:http://www.cnblogs.com/zhguang/p/3257367.html 这里所说的内存分配,主要指的是在堆上的分配,一般的,对象的内存分配都是在堆上进行 ...

  8. Java-杂项: Java中Array和ArrayList区别

    ylbtech-Java-杂项: Java中Array和ArrayList区别 1.返回顶部 1. 1)精辟阐述:可以将 ArrayList想象成一种“会自动扩增容量的Array”. 2)Array( ...

  9. github结合TortoiseGit使用sshkey,无需每次输入账号和密码

    首先需要明确,github上支持三种方式进行项目的clone    https,ssh,subversion ssh的方式 git@github.com:用户名/版本库t.git            ...

  10. [转自百度贴吧-本人亲测有效]Adobe XD 打开立即闪退问题修复

    出现闪退的原因还是因为缺少C++组件, 下载 DirectXRepairV3.7软件 原文: https://tieba.baidu.com/p/5961511474 软件下载: http://xia ...