hdu 5437 Alisha’s Party 模拟 优先队列
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.
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.
#include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm> #define pb push_back using namespace std; const int maxn=+; struct Node
{
int v,id;
bool operator <(const Node&x)const
{
if(x.v==v)
return x.id<id;
return v<x.v;
}
};
struct Time
{
int tim,num;
};
Time time[maxn];
char name[maxn][];
Node ord[maxn];
int ans[maxn]; bool cmp(Time x,Time y)
{
return x.tim<y.tim;
} priority_queue<Node>que; int main()
{
int test;
scanf("%d",&test);
while(test--){
int n,m,q;
scanf("%d %d %d",&n,&m,&q);
for(int i=;i<n;i++){
scanf("%s %d",&name[i],&ord[i].v);
ord[i].id=i;
} for(int i=;i<m;i++){
scanf("%d %d",&time[i].tim,&time[i].num);
} sort(time,time+m,cmp); while(!que.empty())
que.pop(); int now=,len=;
for(int j=;j<m;j++){
while(now<time[j].tim){
que.push(ord[now]);
now++;
}
while(time[j].num--){
ans[len++]=que.top().id;
que.pop();
if(que.empty())
break;
}
}
while(now<n){
que.push(ord[now++]);
}
while(!que.empty()){
ans[len++]=que.top().id;
que.pop();
}
int c;
for(int i=;i<q-;i++){
scanf("%d",&c);
printf("%s ",name[ans[c-]]);
}
scanf("%d",&c);
printf("%s\n",name[ans[c-]]);
}
return ;
}
hdu 5437 Alisha’s Party 模拟 优先队列的更多相关文章
- HDU 5437 Alisha’s Party (优先队列模拟)
题意:邀请k个朋友,每个朋友带有礼物价值不一,m次开门,每次开门让一定人数p(如果门外人数少于p,全都进去)进来,当最后所有人都到了还会再开一次门,让还没进来的人进来,每次都是礼物价值高的人先进.最后 ...
- 优先队列 + 模拟 - HDU 5437 Alisha’s Party
Alisha’s Party Problem's Link Mean: Alisha过生日,有k个朋友来参加聚会,由于空间有限,Alisha每次开门只能让p个人进来,而且带的礼物价值越高就越先进入. ...
- hdu 5437 Alisha’s Party 优先队列
Alisha’s Party Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/contests/contest_sh ...
- 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 ...
- HDU 1103 Flo's Restaurant(模拟+优先队列)
Flo's Restaurant Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDU 5437 Alisha’s Party
题意:有k个人带着价值vi的礼物来,开m次门,每次在有t个人来的时候开门放进来p个人,所有人都来了之后再开一次门把剩下的人都放进来,每次带礼物价值高的人先进,价值相同先来先进,q次询问,询问第n个进来 ...
- HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011亚洲北京赛区网络赛)
HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011 亚洲北京赛区网络赛题目) Eliminate Witches! Time Limit: 2000/1000 ...
- hdu6136[模拟+优先队列] 2017多校8
有点麻烦.. /*hdu6136[模拟+优先队列] 2017多校8*/ #include <bits/stdc++.h> using namespace std; typedef long ...
- hdu 5437(优先队列模拟)
Alisha’s Party Time Limit: 3000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) ...
随机推荐
- spark sql 访问hive数据时找不mysql的解决方法
我尝试着在classpath中加n入mysql的驱动仍不行 解决方法:在启动的时候加入参数--driver-class中加入mysql 驱动 [hadoop@master spark-1.0.1-bi ...
- input、select等表单元素的对齐问题
今天在写页面时,发现了一个问题,当INPUT.SELECT及用图片做的button放在一起(并排放一起)时,没法子对齐,自己以不愿再加其他代码.也不愿使用JS来实现图片button的效果,试好半天,发 ...
- 黑马程序员——JAVA基础之函数,重载,内存结构
------- android培训.java培训.期待与您交流! ---------- 函数: 什么是函数? • 函数就是定义在类中的具有特定功能的一段独立小程序. • 函数也称为方法. 函数的格 ...
- matlab 工具之各种降维方法工具包,下载及使用教程,有PCA, LDA, 等等。。。
最近跑深度学习,提出的feature是4096维的,放到我们的程序里,跑得很慢,很慢.... 于是,一怒之下,就给他降维处理了,但是matlab 自带的什么pca( ), princomp( )函数, ...
- -aborted-exception-during-the-exce
http://stackoverflow.com/questions/20988445/how-to-avoid-response-end-thread-was-being-aborted-excep ...
- OSI安全体系结构
建立七层模型主要是为解决异种网络互连时所遇到的兼容性问题.它的最大优点是将服务.接口和协议这三个概念明确地区分开来;也使网络的不同功能模块分担起 不同的职责.也就是说初衷在于解决兼容性,但当网络发展到 ...
- linux服务之nfs
开发语言:rpc编程环境 服务器端:在linux平台下部署 客户端:一般是cli界面下的mount命令 相关包:rpcbind,nfs-utils 背景 http://nfs.sourceforge. ...
- 【转】WMI使用的WIN32_类库名
ShadowBy--Win32_ShadowContext--Win32_ShadowCopy--Win32_ShadowDiffVolumeSupport--Win32_ShadowFor--Win ...
- lambda 的使用汇总
d=lambda x:x+1print(d(10))lambda 相当于一个轻量函数返回 d=lambda x:x+1 if x>0 else "error"print(d( ...
- 百度ueditor学习使用
1.下载ueditor解压 2. jsp里存放着开发所用到的jar包,导入项目即可 前端页面代码如下: <center> <form action="" meth ...