Problem Description
Princess Alisha invites her friends to come to her birthday party. Each of her friends will bring a gift of some value v,
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 p people
enter her castle. If there are less than p 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 n Please
tell Alisha who the n−th person
to enter her castle is.
 

Input
The first line of the input gives the number of test cases, T ,
where 1≤T≤15.

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

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

Each of the following m lines
contains two integers t(1≤t≤k) and p(0≤p≤k) separated
by a blank. The door will open right after the t−th person
arrives, and Alisha will let p friends
enter her castle.

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

Note: there will be at most two test cases containing n>10000.
 

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

这题可以用set或者优先队列模拟一下,每次在指定的时间读入指定的人数,这些人按照价值从大到小排序,然后当门打开的时候记录它的信息,便于待会输出结果,这里有一点要注意,就是最后m个指令读完后还有人在外面,那么把要这些人都按照规则放入门内。

#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<string>
#include<algorithm>
using namespace std;
#define ll long long
#define inf 999999999
#define maxn 150060
char s[maxn][205],str[maxn][205];
int v[maxn];
struct node{
int idx,v;
}a,temp,temp1; bool operator<(node a,node b){
if(a.v==b.v)return a.idx<b.idx;
else return a.v>b.v;
}
multiset<node>myset;
multiset<node>::iterator it; struct node1{
int t,num;
}b[maxn]; bool cmp(node1 a,node1 b){
return a.t<b.t;
} int main()
{
int n,m,i,j,T,t,num,tot,now,c,q,ans;
scanf("%d",&T);
while(T--)
{
scanf("%d%d%d",&n,&m,&q);
for(i=1;i<=n;i++){
scanf("%s%d",s[i],&v[i]);
}
for(i=1;i<=m;i++){
scanf("%d%d",&b[i].t,&b[i].num);
}
sort(b+1,b+1+m,cmp); tot=0;now=0;
myset.clear();
for(i=1;i<=m;i++){
while(now<b[i].t){
now++;
a.idx=now;a.v=v[now];
myset.insert(a);
}
ans=0;
while(ans<b[i].num){
if(myset.empty())break;
ans++;
it=myset.begin();
temp=*it;
tot++;
strcpy(str[tot],s[temp.idx]);
myset.erase(it);
} }
while(now<n){
now++;
a.idx=now;a.v=v[now];
myset.insert(a);
}
while(tot<n){
it=myset.begin();
temp=*it;
tot++;
strcpy(str[tot],s[temp.idx]);
myset.erase(it);
} for(i=1;i<=q;i++){
scanf("%d",&c);
if(i==q){
printf("%s\n",str[c]);
}
else printf("%s ",str[c]);
}
}
return 0;
}

hdu5437 Alisha’s Party的更多相关文章

  1. HDU5437 Alisha’s Party (优先队列 + 模拟)

    Alisha’s Party Time Limit: 3000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) ...

  2. HDU5437 Alisha’s Party 优先队列

    点击打开链接 可能出现的问题: 1.当门外人数不足p人时没有判断队列非空,导致RE. 2.在m次开门之后最后进来到一批人没有入队. 3.给定的开门时间可能是打乱的,需要进行排序. #include&l ...

  3. Alisha’s Party (HDU5437)优先队列+模拟

    Alisha 举办聚会,会在一定朋友到达时打开门,并允许相应数量的朋友进入,带的礼物价值大的先进,最后一个人到达之后放外面的所有人进来.用优先队列模拟即可.需要定义朋友结构体,存储每个人的到达顺序以及 ...

  4. hdu 5437 Alisha’s Party 模拟 优先队列

    Problem Description Princess Alisha invites her friends to come to her birthday party. Each of her f ...

  5. HDU 5437 Alisha’s Party (优先队列)——2015 ACM/ICPC Asia Regional Changchun Online

    Problem Description Princess Alisha invites her friends to come to her birthday party. Each of her f ...

  6. hdu 5437 Alisha’s Party 优先队列

    Alisha’s Party Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/contests/contest_sh ...

  7. Alisha’s Party(队列)

    Alisha’s Party Time Limit: 3000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) ...

  8. Alisha's Party

    Alisha’s Party Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid ...

  9. 优先队列 + 模拟 - HDU 5437 Alisha’s Party

    Alisha’s Party Problem's Link Mean: Alisha过生日,有k个朋友来参加聚会,由于空间有限,Alisha每次开门只能让p个人进来,而且带的礼物价值越高就越先进入. ...

随机推荐

  1. spring ioc踏出第一步

    spring IOC(容器) AOP(面向切面编程) IOC容器:他的功能就是可以整合像 Structs2 .Hibernate.Mybatis: IOC:控制反转:所谓的控制就是控制资源的获取方法, ...

  2. kubernets之job资源

    一  介绍job资源 1.1   前面介绍的RC,RS,DS等等,管控的pod都是需要长期持久的运行的应用,但是尝试考虑另外一种场景,在微服务的场景下,有些pod的作用就是需要 执行完一些命令之后正常 ...

  3. 误删除SAP ECC中的profile文件

    环境:ECC6.0 EHP4  FOR ORACLE ON WINDWS X64下 今天在RZ10配置系统参数文件的时候,不小心错删除了instance profile文件,这下惨了,这是操作系统层级 ...

  4. [Usaco2008 Mar]牛跑步

    题目描述 BESSIE准备用从牛棚跑到池塘的方法来锻炼. 但是因为她懒,她只准备沿着下坡的路跑到池塘, 然后走回牛棚. BESSIE也不想跑得太远,所以她想走最短的路经. 农场上一共有M (1 < ...

  5. InnoDB事务篇

    1.解决数据更新丢失的问题 1)LBCC:基于锁的并发控制.让操作串行化执行.效率低. 2)MVCC:基于版本的并发控制.使用快照形式.效率高.读写不冲突.主流数据库都是使用的MVCC. 2.Inno ...

  6. Java流程控制与Scanner类的使用

    Java流程控制与Scanner类的使用 Scanner类 Scanner类可以使程序接受键盘输入,实现人机交互 一个完整的Scanner的使用例子: //创建一个扫描器对象,用于接收键盘数据 Sca ...

  7. 如何在 crontab 中让 source ~/.bashrc 生效

    cron 是许多类 Unix 操作系统中都自带的用来调度定时任务的工具,定时任务的配置是写在 crontab 文件中的,但是 crontab 文件不允许直接编辑,一般都是通过命令 crontab -e ...

  8. pyinstaller打包shotgun有关的程序

    By 鬼猫猫 http://www.cnblogs.com/muyr/ 背景 使用pyinstaller打包跟shotgun有关的程序后,在自己电脑上运行都OK,但是编译好的exe在其他人的电脑上运行 ...

  9. python工业互联网应用实战3—Django Admin列表

    Django Admin笔者使用下来可以说是Django框架的开发利器,业务model构建完成后,我们就能快速的构建一个增删查改的后台管理框架.对于大量的企业管理业务开发来说,可以快速的构建一个可发布 ...

  10. 淘宝APP消息推送模型

    为什么到了2020年,"统一推送联盟"依旧无法起显著作用? - 知乎 https://www.zhihu.com/question/370632447 https://mp.wei ...