标签:scan 重要 sign amp bool private graph strong time
Time Limit: 1000MS | Memory Limit: 65536K | |||
Total Submissions: 7646 | Accepted: 2710 | Special Judge |
Description
Input
Output
Sample Input
5 1 10 2 4 3 6 5 8 4 7
Sample Output
4 1 2 3 2 4
Hint
Time 1 2 3 4 5 6 7 8 9 10Other outputs using the same number of stalls are possible.
Stall 1 c1>>>>>>>>>>>>>>>>>>>>>>>>>>>
Stall 2 .. c2>>>>>> c4>>>>>>>>> .. ..
Stall 3 .. .. c3>>>>>>>>> .. .. .. ..
Stall 4 .. .. .. c5>>>>>>>>> .. .. ..
#include<iostream> #include<cstdio> #include<queue> #include<algorithm> using namespace std; struct node { int l,r,n; bool operator <(const node &b)const { return r>b.r||(r==b.r&&l>b.l); } }a[50005]; priority_queue <node> q; int u[50005]; bool cmp(node a,node b) { return a.l<b.l||(a.l==b.l&&a.r<b.r); } int main() { int n,m; while(~scanf("%d",&n)) { int ans=1; for(int i=1;i<=n;i++) { scanf("%d%d",&a[i].l,&a[i].r); a[i].n=i; } sort(a+1,a+n+1,cmp); q.push(a[1]); u[a[1].n]=1; for(int i=2;i<=n;i++) { if(!q.empty()&&q.top().r<a[i].l){ u[a[i].n]=u[q.top().n]; q.pop(); } else{ ans++; u[a[i].n]=ans; } q.push(a[i]); } printf("%d\n",ans); for(int i =1;i<=n;i++){ printf("%d\n",u[i]); } while(!q.empty()) // 尤其重要,排空队列 q.pop(); } }
POJ 3190 Stall Reservations (优先队列)C++
标签:scan 重要 sign amp bool private graph strong time
原文地址:http://www.cnblogs.com/ygtzds/p/7425474.html