poj3190(贪心,优先队列)
来源:互联网 发布:ds是什么意思网络用语 编辑:程序博客网 时间:2024/05/29 16:37
#include<stdio.h>#include<string.h>#include<algorithm>#include<queue>using namespace std;struct p{ int x; int y; int z; friend bool operator<(p n1,p n2)//维护一个优先队列 { return n1.y>n2.y; }} a[50010];bool cmp(p x,p y){ if(x.x==y.x) return x.y<y.y; return x.x<y.x;//按照开始时间从小到大排序}int main(){ int t; int s[50010]; while(~scanf("%d",&t)) { memset(s,0,sizeof(s)); for(int i=0; i<t; i++) { scanf("%d%d",&a[i].x,&a[i].y); a[i].z=i;//记录位置 } sort(a,a+t,cmp); priority_queue<p>Q; Q.push(a[0]); s[a[0].z]=1;//记录使用的机器序号 int sum=2; for(int i=1; i<t; i++) { if(Q.top().y>=a[i].x) s[a[i].z]=sum++; else { s[a[i].z]=s[Q.top().z]; Q.pop(); } Q.push(a[i]); } printf("%d\n",sum-1); for(int i=0; i<t; i++) printf("%d\n",s[i]); } return 0;}
0 0
- poj3190(贪心,优先队列)
- POJ3190 Stall Reservations (贪心+优先队列)
- poj3190 (mulitset贪心)
- poj3190(区间贪心)
- 贪心(好题)--poj3190
- POJ3190:Stall Reservations(贪心)
- poj3190 贪心
- poj1042(贪心+优先队列)
- POJ1456Supermarket(贪心+优先队列)
- poj3465(贪心+优先队列)
- poj2431Expedition(贪心,优先队列)
- 推销员(优先队列+贪心)
- Sunscreen (贪心+优先队列)
- #POJ3190#Stall Reservations(贪心 -> 冲突分配)
- 贪心算法--畜栏保留问题(poj3190 )
- hdu 2850(贪心+优先队列)
- POJ 2431 Expedition (优先队列+贪心)
- POJ 2431 Expedition (贪心 + 优先队列)
- 算法导论 Exercise2.3-5(implement binary search iteratively)
- AC自动机专题——C
- SQL Server数据类型char、nchar、varchar、nvarchar的区别浅析
- MySQL数据库命名规范及约定
- Android网络图片加载框架的选择
- poj3190(贪心,优先队列)
- 离散数学
- 《看见》读后感
- MAC 下面MySQL的字符集修改
- python3.6更新bs4
- CCF修地铁
- 算法设计作业7
- 四款linux操作系统总有一款适合你
- 关于const int *p与 int *const p的区别