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>>>>>>>>> .. .. ..
1 #include<stdio.h> 2 #include<string.h> 3 #include<algorithm> 4 #include<iostream> 5 #include<queue> 6 using namespace std; 7 struct node 8 { 9 int a; 10 int b; 11 int c; 12 bool operator<(const node &c)const 13 { 14 if(b==c.b) 15 return a>c.a; 16 return b>c.b; 17 } 18 } d[60000]; 19 priority_queue<node> q; 20 int s[60000]; 21 bool cmp(struct node a,struct node b) 22 { 23 if(a.a==b.a) 24 return a.b<b.b; 25 return a.a<b.a; 26 } 27 int main() 28 { 29 int a,b,i,j,n=1; 30 scanf("%d",&a); 31 for(i=1; i<=a; i++) 32 { 33 scanf("%d%d",&d[i].a,&d[i].b); 34 d[i].c=i; 35 } 36 sort(d+1,d+a+1,cmp); 37 q.push(d[1]); 38 s[d[1].c]=1; 39 for(i=2; i<=a; i++) 40 { 41 int x=q.top().b; 42 if(x<d[i].a) 43 { 44 s[d[i].c]=s[q.top().c]; 45 q.pop(); 46 } 47 else 48 { 49 n++; 50 s[d[i].c]=n; 51 } 52 q.push(d[i]); 53 } 54 printf("%d\n",n); 55 for(i=1; i<=a; i++) 56 printf("%d\n",s[i]); 57 }
poj 3190 Stall Reservations(贪心),布布扣,bubuko.com
poj 3190 Stall Reservations(贪心)
原文地址:http://www.cnblogs.com/Xacm/p/3825593.html