HDU 5437 Alisha’s Party(优先队列+模拟)

题目地址:点击打开链接

题意:小明有k个朋友,他家太小,他过生日的时候每次只能让一部分人进,开m次门,每次当第t个人来的时候,他会让p个人进(这p个人的礼物价值必须是来的人里面高的那几个,如果他们带的礼物的价值相同,则先来的进),而他有q次询问,第i个进来的人是谁

思路:参考大神的代码看懂了思路,结果写了自己的代码wrong了无数发,最后直接对着大神的代码改,改到倒数第二行一个变量写错了,改了直接就A了,都是泪啊

AC代码:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <cstring>
#include <climits>
#include <cmath>

using namespace std;

const int maxn = 150010;

struct node
{
    int value;
    int id;
    bool operator < (const node &b) const
    {
        if(value != b.value)
            return value < b.value;
        else
            return id > b.id;
    }
}a[maxn];

int C[maxn],I[maxn];
char name[maxn][210];

int main()
{
    int t;
    int N,M,Q,i;
    struct node ll;
    priority_queue<node> que;
    scanf("%d",&t);
    while(t--)
    {
        memset(C,0,sizeof(C));
        scanf("%d%d%d",&N,&M,&Q);
        for(i=1; i<=N; i++)
        {
            scanf("%s%d",name[i],&a[i].value);
            a[i].id = i;
        }
        int u,v;
        for(i=0; i<M; i++)
        {
            scanf("%d%d",&u,&v);
            C[u] = v;
        }
        int p = 0,n = 0;
        for(i=1; i<=N; i++)
        {
            que.push(a[i]);
            n = C[i];
            while(!que.empty() && n)
            {
                ll = que.top();
                I[++p] = ll.id;
                que.pop();
                n--;
            }
        }
        while(!que.empty())
        {
            ll = que.top();
            I[++p] = ll.id;
            que.pop();
        }
        int x;
        for(i=1; i<=Q; i++)
        {
            scanf("%d",&x);
            printf("%s%c",name[I[x]],i == Q ? '\n' : ' ');
        }
    }
    return 0;
}

大神地址: 点击打开链接


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值