poj 1456 Supermarket 贪心 并查集优化
来源:互联网 发布:电脑版电视直播软件 编辑:程序博客网 时间:2024/05/22 07:56
按价值排序后由大到小加进结果,贪心的放在最后的时间里如果某个时间已经占满往前放这时要用并查集维护这天前面没有占满的最后一天
#include<cstdio>#include<algorithm>#include<cstring>#include<cstdlib>#include<queue>#define maxn 10015using namespace std;int n;struct node{ int mo,ti;}no[maxn];int fa[maxn];int getFa(int pre){ if(pre == fa[pre])return pre; fa[pre] = getFa(fa[pre]); return fa[pre];}bool cmp(node no1,node no2){ return no1.mo>no2.mo;}int main(){ while(scanf("%d",&n)!=EOF) { int time = -1; for(int i=1;i<=n;i++){ scanf("%d %d",&no[i].mo,&no[i].ti); time = max(time,no[i].ti);} sort(no+1,no+n+1,cmp); for(int i=0;i<=time;i++)fa[i] = i; int sum = 0; for(int i=1;i<=n;i++) { int pre = getFa(no[i].ti); if(pre) { fa[pre] = pre-1; sum+=no[i].mo; } } printf("%d\n",sum); } return 0;}
0 0
- POJ 1456 Supermarket(贪心算法,可用并查集优化)
- Supermarket poj 1456 贪心+并查集优化
- POJ-1456 Supermarket(贪心,并查集优化)
- poj 1456 Supermarket 贪心 并查集优化
- POJ-1456 Supermarket 贪心 并查集优化
- poj 1456 Supermarket (贪心, 并查集)
- POJ 1456 Supermarket【贪心 + 并查集】
- poj 1456 - Supermarket(贪心+并查集)
- poj 1456 Supermarket (贪心+并查集)
- POJ 1456 Supermarket【贪心+并查集】
- POJ 1456 Supermarket [贪心+并查集]
- Supermarket poj 1456 (贪心,并查集)
- POJ-1456 Supermarket【贪心+并查集】
- 【经典贪心】poj 1456 Supermarket (贪心, 并查集)
- [POJ 1456]Supermarket[贪心][优先队列or并查集优化]
- POJ 1456 Supermarket(贪心 + 并查集 )
- POJ 1456 supermarket(贪心加并查集)
- Supermarket -- 贪心 + 并查集
- 记一次int值返解析为0·
- **MYSQL** 系列五
- 在WordPress主题中使用Font Awesome
- SQL Server恢复数据库解决用户已经存在问题
- android-Notification.Action
- poj 1456 Supermarket 贪心 并查集优化
- APP开发实战117-APP图片优化
- android Binder 学习 博客链接
- 【ES6学习笔记】-----箭头函数与symbol
- POJ-2586-Y2K Accounting Bug
- **MYSQL** 系列六
- Android for work总结(上)
- QGraphicsPixmapItem与QGraphicsScene的编程实例 图标拖动渐变效果
- python笔记---需求文件requirements.txt的创建及使用