poj1456 Supermarket【优先队列】
来源:互联网 发布:数据分析常用公式 编辑:程序博客网 时间:2024/06/17 15:51
题目链接:http://poj.org/problem?id=1456
题意:有一家商场,有n件物品要卖,每件物品,必须在di天前卖出,才能获利pi元,每天只能卖一件商品,问你怎样安排,才能使得获利最大
解析:贪心,从截止日期最大的开始枚举天数,如果大于这个截止日期的就压到优先队列里面,优先队列每次拿出来的是最大价格的,这样来维护答案即可
#include <cstdio>#include <cstring>#include <algorithm>#include <queue>using namespace std;const int maxn = 1e5+100;struct node{ int p,d; bool operator < (const node &b)const { return d>b.d; }}a[maxn];int main(void){ int n; while(~scanf("%d",&n)) { for(int i=0;i<n;i++) scanf("%d %d",&a[i].p,&a[i].d); sort(a,a+n); priority_queue<int>q; int ans = 0,j=0; for(int i=a[0].d;i>0;i--) { for(;j<n&&a[j].d>=i;j++) q.push(a[j].p); while(!q.empty()) { ans += q.top(); q.pop(); break; } } printf("%d\n",ans); } return 0;}
阅读全文
0 0
- poj1456 Supermarket【优先队列】
- POJ1456 Supermarket
- poj1456 - Supermarket
- POJ1456 Supermarket
- 【poj1456 】supermarket
- poj1456 Supermarket
- POJ1456 Supermarket 贪心 DP
- poj1456 Supermarket(贪心)
- POJ1456 Supermarket (贪心)
- (advanced) UVA 优先队列+贪心 1316 Supermarket
- UVALive - 2757 Supermarket 贪心+优先队列
- POJ 1456 Supermarket 贪心+优先队列
- UVaLive 2757 Supermarket (贪心+优先队列)
- POJ1456 Supermarket简单贪心(无优化)题解
- poj 1456 Supermarket(贪心+并查集,贪心+优先队列)
- [POJ 1456]Supermarket[贪心][优先队列or并查集优化]
- poj Supermarket(贪心)(并查集)(优先队列)
- poj1456
- 移动端效果之Swiper
- JAVA提高篇(40)--网络编程UDP和TCP
- jsDOM用法讲解
- Android Studio 上传 SVN 忽略文件配置
- java,8种基本数据类型,数据类型,8种,java基础
- poj1456 Supermarket【优先队列】
- 特征选择概述
- 关于Class对象、类加载机制、虚拟机运行时的内存布局的全面解析和推测
- Linux IO复用区别与epoll详解
- 使用wsimport和JAX-WS调用Web Service接口
- sphereface conv64
- Eclipse常用设置
- JavaWeb(四)EL表达式
- 一张图理清ASP.NET Core启动流程