标签:assign get mis red schedule only moment each inter
Time Limit: 1000MS | Memory Limit: 65536K | |||
Total Submissions: 15069 | Accepted: 5270 | 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<string.h> #include<string> #include<algorithm> #include<queue> #include<set> #define ll long long using namespace std; struct node { int id; int l; int r; }p[1000005],temp,now; int vis[1000005]; bool cmp(node x,node y)//将开始处理时间早,处理时间短的放前面 { if(x.l!=y.l) return x.l<y.l; else return x.r<y.r; } bool operator < (node x,node y)//二次处理的时候,将结束时间早,开始时间晚的放前面 { if(x.r!=y.r) return x.r>y.r; else return x.l<y.l; } priority_queue<node>q; int main() { int n; while(~scanf("%d",&n)) { for(int i=0;i<n;i++) { scanf("%d%d",&p[i].l,&p[i].r); p[i].id=i; } sort(p,p+n,cmp); int cnt=1; q.push(p[0]); vis[p[0].id]=1; for(int i=1;i<n;i++) { if(!q.empty()&&q.top().r<p[i].l) { vis[p[i].id]=vis[q.top().id]; q.pop(); } else { cnt++; vis[p[i].id]=cnt; } q.push(p[i]); } printf("%d\n",cnt); for(int i=0;i<n;i++) printf("%d\n",vis[i]); while(!q.empty()) q.pop(); } return 0; }
标签:assign get mis red schedule only moment each inter
原文地址:https://www.cnblogs.com/-citywall123/p/11298590.html