CodeForces - 799B-T-shirt buying (优先队列)

题目链接

 

 1 /*
 2     Name:
 3     Copyright:
 4     Author:
 5     Date: 2018/5/2 16:09:54
 6     Description:优先队列
 7 */
 8 #include <iostream>
 9 #include <cstdio>
10 #include <vector>
11 #include <cstring>
12 #include <queue>
13 using namespace std;
14 const int MAXN = 200005;
15 int price[MAXN];
16 struct tshirt{
17     int index, pri;
18     tshirt(int i){
19         this->index = i;
20         this->pri = price[i] ;
21     };
22     bool operator <(const tshirt& lpm) const {
23         return pri > lpm.pri;
24     }
25 }; 
26 int main()
27 {
28     int n;
29     while (scanf("%d", &n) != EOF) {
30         priority_queue<tshirt> lev[4];
31         memset(price, 0, sizeof(price));
32         for (int i=0; i<n; i++) 
33             scanf("%d", &price[i]);
34         int level;
35         for (int i=0; i<n; i++) {
36             scanf("%d", &level);
37             tshirt demo(i);
38             lev[level].push(demo);
39         }
40         for (int i=0; i<n; i++) {
41             scanf("%d", &level);
42             tshirt demo(i);
43             lev[level].push(demo);
44         }
45         int num, fav;
46         scanf("%d", &num);
47         for (int i=0; i<num; i++) {
48             scanf("%d", &fav);
49             if (lev[fav].empty() ){
50                 cout<<-1<<" ";
51                 continue;
52             }
53             int value = 0;
54             while (!lev[fav].empty() && !value) {
55                 if (price[lev[fav].top().index] == -1) {//去掉重复的 
56                     lev[fav].pop();
57                 } else {
58                     value = 1;
59                     cout<<lev[fav].top().pri<<" ";
60                     price[lev[fav].top().index] = -1;
61                     lev[fav].pop();
62                 }
63             }
64             if (!value){
65                 cout<<-1<<" ";
66             }
67         }
68         cout<<endl;
69     }
70     return 0;
71 }

 

posted @ 2018-05-02 19:29  朤尧  阅读(360)  评论(0编辑  收藏  举报