HDU 5437 Alisha’s Party 优先队列

来源:互联网 发布:python 创建嵌套字典 编辑:程序博客网 时间:2024/04/28 00:42

2015 ACM/ICPC Asia Regional Changchun Online

优先队列模拟,邀请k个朋友,每个朋友带有礼物价值不一,m次开门,每次开门让一定人数p(如果门外人数少于p,全都进去)进来,当最后所有人都到了还会再开一次门,让还没进来的人进来,每次都是礼物价值高的人先进。

最后给出q个数,表示要输出第ni个进来的人的名字

注意:

1.人数等于开门次数,每次开门不进人

2.给的开门时间可能是打乱的,需要重新排列

3.不开门

4.礼物价值相等的,先来的先进


#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>#include <vector>#include <queue>#include <set>#include <map>#include <string>#include <math.h>#include <stdlib.h>#include <time.h>#define maxn 150005using namespace std;struct node{    char name[205];    int v, tp;    friend bool operator <(node a,node b)    {        if(a.v == b.v) return a.tp > b.tp;        return a.v < b.v;    }};node fri[maxn];struct node1{    int t, r;}ask[maxn];bool cmp(node1 a, node1 b){    return a.t < b.t;}int put[maxn], wen[105];int main(){    int t, k, m, p, i, j, ok, now;    scanf("%d", &t);    while(t--)    {        scanf("%d %d %d", &k, &m, &p);        for(i = 0;i < k;i++)        {            scanf("%s %d",fri[i].name, &fri[i].v);            fri[i].tp = i;        }        ask[0].t = -1;        for(i = 0;i < m;i++)            scanf("%d %d", &ask[i].t, &ask[i].r);        for(i = 0;i < p;i++)            scanf("%d", &wen[i]);        priority_queue<node>q;        sort(ask, ask + m, cmp);        now = 0;        ok = 0;        for(i = 1;i <= k;i++)        {            q.push(fri[i - 1]);            if(i == ask[now].t)            {                for(j = 1;j <= ask[now].r&&(!q.empty());j++)                {                    node x = q.top();                    q.pop();                    put[ok++] = x.tp;                }                now++;            }        }        while(!q.empty())        {            node x = q.top();            q.pop();            put[ok++] = x.tp;        }        for(i = 0;i < p;i++)            printf("%s%c", fri[put[wen[i] - 1]].name, i==p-1?'\n':' ');    }}


0 0