hdu 5437Alisha’s Party(优先队列)

题意:邀请k个朋友,每个朋友带有礼物价值不一,m次开门,每次开门让一定人数p(如果门外人数少于p,全都进去)进来,当所有人到时会再开一次,每次都是礼物价值高的人先进。

/*小伙伴最开始gg了,结果发现是开门没排序

1.如果价值相等,先到的进;  

2.开门的时间要进行排序;



Sample Input
1 5 2 3 Sorey 3 Rose 3 Maltran 3 Lailah 5 Mikleo 6 1 1 4 2 1 2 3


#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <algorithm>
#include <cstring>

using namespace std;

struct node
{
    char name[210];
    int value;
} fri[150100];
int ans[150100];
int query[150100];

struct cmp
{
    bool operator()(int i, int j)
    {
        if(fri[i].value==fri[j].value)
            return i>j;
        else return fri[i].value<fri[j].value;
    }
};

int main()
{
    int t;
    int k, m, q;
    int n, p;
    int ansCount, cur;
    int temp, tempnum;
    scanf("%d", &t);
    while(t--)
    {
        priority_queue<int , vector<int>, cmp> qu;
        scanf("%d%d%d", &k, &m, &q);
        ansCount = 0;
        cur = 1;
        for(int i=1; i<=k; i++)
        {
            scanf("%s%d", fri[i].name, &fri[i].value);
        }
        memset(query, 0, sizeof(query));
        for(int i=0; i<m; i++)
        {
            scanf("%d%d", &temp, &tempnum);
            query[temp] = max(query[temp], tempnum);
        }
        for(int i=1; i<=k; i++)
        {
            if(query[i]!=0)
            {
                for(; cur<=i&&cur<=k; cur++)
                {
                    qu.push(cur);
                }
                for(int j=0; j<query[i]&&!qu.empty(); j++)
                {
                    ans[++ansCount] = qu.top();
                    qu.pop();
                }
            }
        }
        for(; cur<=k; cur++) qu.push(cur);
        while(!qu.empty())
        {
            ans[++ansCount] = qu.top();
            qu.pop();
        }
        for(int i=1; i<=q; i++)
        {
            scanf("%d", &n);
            printf("%s%c", fri[ans[n]].name, " 
"[i==q]);
        }
    }
    return 0;
}

  

原文地址:https://www.cnblogs.com/Przz/p/5409761.html