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
 
Source
 
 
 
 
本来是一道简单的模拟题,我却花了很久的时间,一直wa,要跪了
后来还是请教了别人才知道错在哪里了
数据的时间是没有说是有序的,也就是时间的数据不一定是按照顺序给我们的。
所以要先对数据进行排序。
 
以后要时刻记住,输入数据一定要考虑乱序的情况。
 
 
 #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 模拟 优先队列的更多相关文章

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

    题意:邀请k个朋友,每个朋友带有礼物价值不一,m次开门,每次开门让一定人数p(如果门外人数少于p,全都进去)进来,当最后所有人都到了还会再开一次门,让还没进来的人进来,每次都是礼物价值高的人先进.最后 ...

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

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

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

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

  4. 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 ...

  5. HDU 1103 Flo's Restaurant(模拟+优先队列)

    Flo's Restaurant Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  6. HDU 5437 Alisha’s Party

    题意:有k个人带着价值vi的礼物来,开m次门,每次在有t个人来的时候开门放进来p个人,所有人都来了之后再开一次门把剩下的人都放进来,每次带礼物价值高的人先进,价值相同先来先进,q次询问,询问第n个进来 ...

  7. HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011亚洲北京赛区网络赛)

    HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011 亚洲北京赛区网络赛题目) Eliminate Witches! Time Limit: 2000/1000 ...

  8. hdu6136[模拟+优先队列] 2017多校8

    有点麻烦.. /*hdu6136[模拟+优先队列] 2017多校8*/ #include <bits/stdc++.h> using namespace std; typedef long ...

  9. hdu 5437(优先队列模拟)

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

随机推荐

  1. 共享内存+互斥量实现linux进程间通信 分类: Linux C/C++ 2015-03-26 17:14 67人阅读 评论(0) 收藏

    一.共享内存简介 共享内存是进程间通信中高效方便的方式之一.共享内存允许两个或更多进程访问同一块内存,就如同 malloc() 函数向不同进程返回了指向同一个物理内存区域的指针,两个进程可以对一块共享 ...

  2. Java的位运算 待整理

    位运算:二进制运算 Java的异或运算^ 真^假=真 假^真=真 假^假=假 真^真= 假,这四个是在网上copy的例子,真是1,假是0 但它却是说明了Java异或运算的基本法则,那就是:只要两个条件 ...

  3. 使用Animation实现摄像机动画

    项目剧情模块分给了我做,其中很重要的一个功能就是摄像机旋转平移等操作,本来打算使用Camera Path这个插件制作的,但是鉴于项目Unity版本还停留在4.3,低于插件要求版本,另外编辑器做出来是交 ...

  4. LINQ(LINQ to DataSet)

    http://www.cnblogs.com/SkySoot/archive/2012/08/21/2649471.html DataTable.Select()方法使用和 SQL 相似的过滤语法从 ...

  5. mvc:view-controller

    This tag is a shorcut for defining a ParameterizableViewController that immediately forwards to a vi ...

  6. mysql 索引过长1071-max key length is 767 byte

    问题 create table: Specified key was too long; max key length is 767 bytes   原因 数据库表采用utf8编码,其中varchar ...

  7. SQL Server 备份故障

    故障信息如下: 标题: Microsoft SQL Server Management Studio------------------------------备份 对于 服务器“*******”失败 ...

  8. uml类关系

    类间的关系:http://www.open-open.com/lib/view/open1328059700311.html 泛化 . 实现 . 关联 . 组合 . 聚合 . 依赖 泛化是继承类,实现 ...

  9. 解决:mvn archetype:create Abstract class or interface 'org.apache.maven.artifact.repository.ArtifactRepository' cannot be instantiated

    [ERROR] Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:2 .3:create (default- ...

  10. java 实现mysql数据库导出

    package com.zbb.util; import java.io.BufferedReader;import java.io.File;import java.io.FileInputStre ...