poj 2786 Keep the Customer Satisfied(贪心+优先队列)
来源:互联网 发布:mac磁盘权限修复 编辑:程序博客网 时间:2024/05/01 16:29
Input
The first line contains the number n of orders (n can be as large as 800000 for some test cases). It is followed by n lines. Each of which describes an order made of two integer values: the amount of steel (in tons) required for the order (lower than 1000) and its due date (in seconds; lower than 2 x 106 ).
Output
You are required to compute an optimal solution and your program has to write the number of orders that are accepted.
Sample Input
67 158 206 84 93 215 22
Sample Output
4
<a target=_blank href="http://poj.org/problem?id=2786">http://poj.org/problem?id=2786</a>按照任务的截止时间排序,然后使用优先队列,每次累加任务消耗时间,如果所用时间超过了限定时间,则从优先队列中取出时间消耗最大的任务。
#include<iostream>#include<algorithm>#include<string>#include<map>//int dx[4]={0,0,-1,1};int dy[4]={-1,1,0,0};#include<set>//int gcd(int a,int b){return b?gcd(b,a%b):a;}#include<vector>#include<cmath>#include<queue>#include<string.h>#include<stdlib.h>#include<cstdio>#define mod 1e9+7#define ll long longusing namespace std;int n;pair<int,int> x[800001]; int cmp(pair<int,int>a,pair<int,int>b){return a.second<b.second;}int main(){scanf("%d",&n);for(int i=0;i<n;++i){scanf("%d %d",&x[i].first,&x[i].second);//需要的工作时间和截止日期 }sort(x,x+n,cmp); //按截止日期排序 int s=n,sum=0;priority_queue<int> q; //默认是从大到小排序(需要的工作时间)for(int i=0;i<n;++i){q.push(x[i].first);sum+=x[i].first;if(sum>x[i].second){s--;sum-=q.top(); //舍去需要的工作时间最久的 q.pop(); }}printf("%d",s); return 0;}
0 0
- poj 2786 Keep the Customer Satisfied(贪心+优先队列)
- 【POJ】2786-Keep the Customer Satisfied(贪心 + 优先队列,姿势不对就要跪)
- POJ 2786 Keep the Customer Satisfied 优先队列
- POJ 2786 Keep the Customer Satisfied 贪心
- 1153 - Keep the Customer Satisfied(贪心+优先队列)
- uva 1153 - Keep the Customer Satisfied(贪心+优先队列)
- UVA1153-Keep the Customer Satisfied(贪心+优先队列)
- UVa 1153 - Keep the Customer Satisfied (贪心 + 优先队列)
- UVa 1153 Keep the Customer Satisfied (贪心+优先队列)
- 习题8-12 UVA - 1153 Keep the Customer Satisfied 顾客是上帝(优先队列贪心)
- 1153 - Keep the Customer Satisfied(贪心)
- Keep the Customer Satisfied poj 2786
- UVa 1153 Keep the Customer Satisfied 解题报告(贪心)
- UVa 1153 - Keep the Customer Satisfied(贪心)
- UVA 1153 - Keep the Customer Satisfied(贪心)
- Uva 1153 Keep the Customer Satisfied(贪心)
- 【UVa1153】Keep the Customer Satisfied 顾客是上帝(贪心)
- UVALive - 3507 Keep the Customer Satisfied 贪心
- 递归 Java
- C字符串中的'\0'为什么存在
- 小希的迷宫(并查集)
- android studio 无法在可视化页面预览布局文件
- 一个非常实用的带验证码的模拟登陆实例
- poj 2786 Keep the Customer Satisfied(贪心+优先队列)
- 优盘启动盘进入系统后识别不了硬盘
- java中对数组的操作
- php模版引擎(smarty3)—优化(定界符,避免和其他语言的冲突)
- ubuntu搭建OpenGrok
- [模板]筛选法求欧拉函数
- 二值图像边缘提取算法C语言实现
- HDN通畅工程
- android AVD 启动时报错(emulator: erroremulator:ERROR:This AVD's configuration is missing a kernel file )