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) ...
随机推荐
- Codeforces Round #373 (Div. 1)
Codeforces Round #373 (Div. 1) A. Efim and Strange Grade 题意 给一个长为\(n(n \le 2 \times 10^5)\)的小数,每次可以选 ...
- spark_updateStateByKey
java核心代码 JavaPairDStream<String, Integer> wordCounts = pair.updateStateByKey(new Function2< ...
- ed编辑器使用
evilxr@IdeaPad:/tmp$ ed aa.c 0 a enter another words hello nice www.evilxr.com . w aa.c 46 q a 表示添加内 ...
- html-javascript前端页面刷新重载的方法汇总
记得我在兴安得力实习要转正的时候,我领导象征性的给我出了一套测试题目,里面就有js闭包和页面刷新等题目.今天把很久之前的测试题目之一,js页面刷新的方法以及页面自动刷新跳转和返回上一页和下一页等方法总 ...
- COM ,Threading Models,apartments,RPC
Component Object Model (COM) https://msdn.microsoft.com/en-us/library/windows/desktop/ms680573%28v=v ...
- C语言调试的几种方法
linux系统下,在不gdb调试的情况下,我们如何解决程序崩溃问题呢?首先想到的就是添加log日志信息,其次还有以下几种方法可以帮助我们分析存在的问题: (一)add2line 程序崩溃时会打出一些崩 ...
- Git-rebase与merge小结
git merge是用来合并两个分支的. git merge b # 将b分支合并到当前分支 同样 git rebase b,也是把 b分支合并到当前分支 ---------------------- ...
- QQ登入(2)获取用户信息
private void initView() { mUserInfo = (TextView) findViewById(R.id.user_info); mUserLogo = (ImageVie ...
- C#学习之LinqtoSql类的简单例子
LinqtoSql类把访问.操作数据库的细节封装了起来,把连接操作数据库变得相当简单.下面是简单的例子. 第一步:添加LinqtoSql类 1.创建一个控制台应用程序项目,下载一个NrothWind ...
- JSP 相关试题(二)
填空题 1.W3C是指___万维网联盟_______. 2.Internet采用的通信协议是___TCP/IP___. 3.当今比较流行的技术研发模式是__C/S__和__B/S__的体系结构来实现的 ...