【优先队列】POJ3614-Sunscreen

参考:❀

 1 #include
 2 #include
 3 #include
 4 #include
 5 using namespace std;
 6 const int MAXN=2500+50;
 7 struct rec
 8 {
 9     int a,b;
10     bool operator < (const rec& x) const
11     {
12         return a<x.a;
13     }
14 };
15 
16 rec cow[MAXN],sunscreen[MAXN];
17 int C,L,ans=0;
18 
19 int main()
20 {
21     scanf("%d%d",&C,&L);
22     for (int i=0;i"%d%d",&cow[i].a,&cow[i].b); //a:min b:max
23     for (int i=0;i"%d%d",&sunscreen[i].a,&sunscreen[i].b);//a:effect b:num
24     priority_queue< int,vector<int>,greater<int> > pque;
25     sort(cow,cow+C);
26     sort(sunscreen,sunscreen+L);
27     int j=0;
28     for (int i=0;i)
29     {
30         while (jsunscreen[i].a)
31         {
32             pque.push(cow[j].b);
33             j++;
34         }
35         while (!pque.empty() && sunscreen[i].b)//莫忘队列为空时也不执行 
36         {
37             int temp=pque.top();
38             pque.pop();
39             if (tempcontinue;
40             sunscreen[i].b--;
41             ans++;
42         }
43     }
44     cout<endl;
45     return 0;
46 }

 

转载于:https://www.cnblogs.com/iiyiyi/p/4652365.html

你可能感兴趣的:(【优先队列】POJ3614-Sunscreen)