CodeForces - 799B-T-shirt buying (优先队列)
Posted 朤尧
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 }
以上是关于CodeForces - 799B-T-shirt buying (优先队列)的主要内容,如果未能解决你的问题,请参考以下文章