poj 3190
来源:互联网 发布:fs2you mac 编辑:程序博客网 时间:2024/06/06 01:55
要用优先队列去维护结束的时间
代码如下
#include<cstdio>#include<iostream>#include<cstring>#include<algorithm>#include<queue>using namespace std;const int maxn=50005;int used[maxn];struct Node{int pos,l,r;bool operator <(const Node &a) const{return r>a.r||(r==a.r&&l>a.l);}}a[maxn];priority_queue<Node> q; bool cmp(Node a,Node b){if(a.l==b.l) return a.r<b.r;return a.l<b.l;}int main(){int n;scanf("%d",&n);for(int i=0;i<n;i++){scanf("%d%d",&a[i].l,&a[i].r);a[i].pos=i;}int ans=1;sort(a,a+n,cmp);while(!q.empty()) q.pop();q.push(a[0]);used[a[0].pos]=1;for(int i=1;i<n;i++){if(!q.empty()&&q.top().r<a[i].l){used[a[i].pos]=used[q.top().pos];q.pop();}else{ans++;used[a[i].pos]=ans;}q.push(a[i]);}printf("%d\n",ans);for(int i=0;i<n;i++)printf("%d\n",used[i]);return 0;}
阅读全文
0 0
- POJ 3190
- poj 3190
- 【POJ】3190
- poj 3190
- poj 3190
- poj 3190 Stall Reservations
- POJ-3190-Stall Reservations
- POJ-3190-Stall Reservations
- POJ 3190 Stall Reservations
- POJ-3190-Stall Reservations
- poj 3190Stall Reservations
- poj 3190 Stall Reservations
- poj 3190 Stall Reservations1
- poj 3190 Stall Reservations
- POJ 3190 Stall Reservations
- POJ 3190 Stall Reservations
- POJ 3190 解题报告
- poj 3190 Stall Reservations
- java 图形用户界面编程 之 事件处理
- JavaScript实现rgb转为16进制
- HDU 2813 One fihgt one(KM算法解决最小权值匹配)
- 感触
- VxWorks讨论群 166692882
- poj 3190
- epoll源码分析(转)
- vSphere VDDK LAN-free 备份原理
- Unsafe与CAS
- 机器学习python库解
- maven web工程创建
- STL(二十三)排序算法
- Confluence集成实践:2:Confluence的RestAPI
- 大数据学习7:Hadoop Yarn 的调优整理