• CodeForces


    题目链接

     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 }
  • 相关阅读:
    菜鸟系列k8s——快速部署k8s集群(3)
    菜鸟系列docker——docker容器(7)
    菜鸟系列Fabric源码学习 — 区块同步
    菜鸟系列Fabric源码学习 — peer节点启动
    菜鸟系列Fabric源码学习 — orderer服务启动
    递归科赫雪花
    汉诺塔递归函数hanoi
    字符串格式化与.format()
    turtle风轮绘制
    接口签名2
  • 原文地址:https://www.cnblogs.com/slothrbk/p/8982039.html
Copyright © 2020-2023  润新知