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

思路:题目比较好懂的模拟题,用一个优先队列即可

          模拟的时候要注意最后还会再开一次门,把剩下的人全部放进来,开门的时间并不一定是递增的,要自己排个序,还有就是要注意开门的时候是2 5这种数据,就是到第二个人到了开门,然后可以放5个人进来,这样不处理的话会RE


#include<bits/stdc++.h>
using namespace std;
const int maxn = 150000+7;
struct Node
{
	char name[205];
	int w;
	int id;
	bool operator < (const Node&a)const
	{
		if(w==a.w)
			return id>a.id;
		return w<a.w;
	}
}p[maxn];
struct node
{
	int t;
	int peo;
}pp[maxn];
bool cmp(node a,node b)
{
	return a.t<b.t;
}
int ans[maxn];
int main()
{
    int T;
	scanf("%d",&T);
	while(T--)
	{
		memset(ans,0,sizeof(ans));
		int n,m,q;
		scanf("%d%d%d",&n,&m,&q);
        for(int i = 1;i<=n;i++)
		{
			scanf("%s%d",p[i].name,&p[i].w);
			p[i].id = i;
		}
        for(int i = 1;i<=m;i++)
            scanf("%d%d",&pp[i].t,&pp[i].peo);
        sort(pp+1,pp+1+m,cmp); 
		priority_queue<Node>que;
		int cnt = 1;int res = 1;
        for(int i = 1;i<=m;i++)
		{
			int tim = pp[i].t;
            for(;cnt<=tim;cnt++)
			   que.push(p[cnt]);
			int lim = pp[i].peo;
			for(int j = 1;j<=lim&&!que.empty();j++)
			{
				Node tmp = que.top();que.pop();
				ans[res++]=tmp.id;
			}
		}
		for(;cnt<=n;cnt++)
			que.push(p[cnt]);
		while(!que.empty())
		{
			Node tmp = que.top();
			que.pop();
			ans[res++]=tmp.id;
		}

		for(int i = 1;i<q;i++)
		{
			int x;
			scanf("%d",&x);
			printf("%s ",p[ans[x]].name);
		}
		int x;scanf("%d",&x);
		printf("%s\n",p[ans[x]].name);
	}
}


Description

Princess Alisha invites her friends to come to her birthday party. Each of her friends will bring a gift of some value  , and all of them will come at a different time. Because the lobby is not large enough, Alisha can only let a few people in at a time. She decides to let the person whose gift has the highest value enter first. 

Each time when Alisha opens the door, she can decide to let   people enter her castle. If there are less than   people in the lobby, then all of them would enter. And after all of her friends has arrived, Alisha will open the door again and this time every friend who has not entered yet would enter. 

If there are two friends who bring gifts of the same value, then the one who comes first should enter first. Given a query   Please tell Alisha who the   person to enter her castle is.

Input

The first line of the input gives the number of test cases,   , where 

In each test case, the first line contains three numbers   and   separated by blanks.   is the number of her friends invited where  . The door would open m times before all Alisha’s friends arrive where  . Alisha will have   queries where 

The   of the following   lines gives a string  , which consists of no more than   English characters, and an integer  , separated by a blank.   is the name of the   person coming to Alisha’s party and Bi brings a gift of value 

Each of the following   lines contains two integers   and   separated by a blank. The door will open right after the   person arrives, and Alisha will let   friends enter her castle. 

The last line of each test case will contain   numbers   separated by a space, which means Alisha wants to know who are the   friends to enter her castle. 

Note: there will be at most two test cases containing 

Output

For each test case, output the corresponding name of Alisha’s query, separated by a space.

Sample Input

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

Sample Output

Sorey Lailah Rose


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值