首页 > 其他分享 >HDU 5437 Alisha’s Party(优先队列模拟)

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

时间:2023-06-09 19:06:54浏览次数:40  
标签:HDU 5437 her int will enter Alisha friends


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

          模拟的时候要注意最后还会再开一次门,把剩下的人全部放进来,开门的时间并不一定是递增的,要自己排个序,还有就是要注意开门的时候是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




, 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 



Input


 , 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


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


Sample Output


Sorey Lailah Rose





标签:HDU,5437,her,int,will,enter,Alisha,friends
From: https://blog.51cto.com/u_16156555/6450591

相关文章

  • HDU - 5253 连接的管道 (卡鲁斯卡尔)最小生成树
    TimeLimit: 1000MS MemoryLimit: 32768KB 64bitIOFormat: %I64d&%I64uHDU-5253连接的管道Submit StatusDescription老Jack有一片农田,以往几年都是靠天吃饭的。但是今年老天格外的不开眼,大旱。所以老Jack决定用管道将他的所有相邻的农田全部都串联起......
  • HDU - 1114 Piggy-Bank (完全背包)
    TimeLimit: 1000MS MemoryLimit: 32768KB 64bitIOFormat: %I64d&%I64uHDU-1114Piggy-BankSubmit StatusDescriptionBeforeACMcandoanything,abudgetmustbepreparedandthenecessaryfinancialsupportobtained.Themainincomeforthis......
  • HDU - 2473 (并查集+设立虚父节点(马甲))
    涉及到并查集的删除操作,比较复杂,可以利用虚设父节点的方法:例如:有n个节点,进行m次操作.首先将0~n-1的节点的父节点设置为i+n,n~2n+1的节点的父节点设置为本身,有m次操作,所以要用到m个虚节点,例如0,1,2,3,4,5的父节点为7,8,9,10,11,把他们插入2的集合,所以他们的根节点都为8,当把2从集合......
  • 三个博弈-巴什博奕、威佐夫博弈、尼姆博弈。acm博弈算法笔记HDU 2149,1850,1527
    博弈论(一)、acm博弈基础算法BashGame,NimGame和WythoffGame(即巴什博奕、尼姆博弈、威佐夫博弈)Bash  Game: 同余理论Nim   Game: 异或理论WythoffGame: 黄金分割(二)、三个博弈。1、巴什博奕。只有一堆n个物品,两个人轮流从这堆物品中取物, 规定每次至少取一个,......
  • 树状数组讲解与例题 杭电HDU1166,HDU1556,HDU2689
    树状数组的总结树状数组很巧妙地解决了数列的求和与查找,速度很快。树状数组,它改变数列中某一位,或者求某个区间的和,时间复杂度是O(logN);效率大为改善。下面的图片很好的演示了树状数组的存储原理。(图片来自网络)观察图片,会发现:数组c的每一个元素都管辖着一定范围内的数组a元素的和,比如C......
  • HDU 5542 The Battle of Chibi(树状数组+dp)
    TheBattleofChibiTimeLimit:6000/4000MS(Java/Others)    MemoryLimit:65535/65535K(Java/Others)TotalSubmission(s):1749    AcceptedSubmission(s):621ProblemDescriptionCaoCaomadeupabigarmyandwasgoingtoinvadethewholeSou......
  • ICPC2015(沈阳)HDU5521 建图技巧+最短路
    MeetingTimeLimit:12000/6000MS(Java/Others)  MemoryLimit:262144/262144K(Java/Others)TotalSubmission(s):3533  AcceptedSubmission(s):1136ProblemDescriptionBessieandherfriendElsiedecidetohaveameeting.However,afterFarmerJohndecor......
  • HDU2227(非降子序列的个数)
    题目:http://acm.hdu.edu.cn/showproblem.php?pid=2227题意:给定一个长度为n(n<=100000)的整数序列,求其中的非降子序列的个数。分析:如果n的值比较小,那么就是一个纯粹的dp题。设dp[i]表示以a[i]为结尾非降子序列的个数,其状态转移方程为:      可以看出,这样做的时间复杂度是......
  • HDU4372(第一类斯特林数)
    题目:CounttheBuildings题意:N座高楼,高度均不同且为1~N中的数,从前向后看能看到F个,从后向前看能看到B个,问有多少种可能的排列数。0<N,F,B<=2000首先我们知道一个结论:n的环排列的个数与n-1个元素的排列的个数相等,因为P(n,n)/n=(n-1)!。可以肯定,无论从最左边还是从最右边看,......
  • HDU4633(Polya计数)
    题目:Who'sAuntZhang#include<iostream>#include<string.h>#include<stdio.h>usingnamespacestd;typedeflonglongLL;constLLMOD=10007;LLquick_mod(LLa,LLb){LLans=1;a%=MOD;while(b){if(b&1......