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) ...
随机推荐
- HDU 1003 Max Sum --- 经典DP
HDU 1003 相关链接 HDU 1231题解 题目大意:给定序列个数n及n个数,求该序列的最大连续子序列的和,要求输出最大连续子序列的和以及子序列的首位位置 解题思路:经典DP,可以定义 ...
- 转贴:sudo apt-get install 可以安装的一些软件
Ubuntu 下的一些软件安装sudo apt-get install virtualbox#华主席推荐 2007年年度最佳软件,最佳编辑选择奖得主.....sudo apt-get install ...
- PWM控制led渐变
PWM,中文释义:脉冲宽度调制.它是利用微处理器的数字输出来对模拟电路进行控制的一种非常有效的技术. PWM 是一种对模拟信号电平进行数字编码的方法.通过高分辨率计数器的使用,方波的占空比被调制用来对 ...
- 将caffe训练时loss的变化曲线用matlab绘制出来
1. 首先是提取 训练日志文件; 2. 然后是matlab代码: clear all; close all; clc; log_file = '/home/wangxiao/Downloads/43_ ...
- centos 6.4/redhat 6.4 安装gitlab
一,把所有包升级到最新版本 yum -y upgrade 二,安装最新版ruby 2.1.5 步骤http://my.oschina.net/duolus/blog/348353 三,安装官方给出的o ...
- JSBinding + SharpKit / Coroutine支持
首先得深入了解协程的原理.如果还没有完全理解,建议看这篇: http://wiki.unity3d.com/index.php/CoroutineScheduler 另外还要对 JavaScript ...
- ORA-12547:TNS:lost contact 问题分析思路
ORA-12547:TNS:lost contact sqlplus无法正常登陆数据库 解决思路如下: 1.查看操作系统内核参数是否无误 [oracle@normal adump]$ ulimit - ...
- 重力感应操控(unity iphone)
方案一:speed 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 public var simulateAcceleromet ...
- redis.conf配置文件详解
redis 配置文件示例 # 当你需要为某个配置项指定内存大小的时候,必须要带上单位, # 通常的格式就是 1k 5gb 4m 等酱紫: # # 1k => 1000 bytes # 1kb = ...
- 使用Javascript实现跳转页面和打开新窗口的方法
1.在原来的窗体中直接跳转用 window.location.href="你所要跳转的页面url"; 2.在新窗体中打开页面用: window.open('你所要跳转的页面url' ...