Alisha’s Party

Time Limit: 1 Sec

Memory Limit: 256 MB

题目连接

http://acm.hdu.edu.cn/contests/contest_showproblem.php?pid=1001&cid=621

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

HINT

题意

有一个人会开门,然后让拥有礼物价值最高的人进来,然后问你第k个人进来的人是谁

题解:

优先队列咯,模拟模拟就好了

代码:

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <queue>
#include <iomanip>
#include <string>
#include <ctime>
#include <list>
#include <bitset>
typedef unsigned char byte;
#define pb push_back
#define input_fast std::ios::sync_with_stdio(false);std::cin.tie(0)
#define local freopen("in.txt","r",stdin)
#define pi acos(-1)using namespace std;
const int maxn = 150000 + 500;
typedef pair<int,int>dl;
struct node
{int val;int idx;friend bool operator < (const node & a,const node & b){return a.val < b.val || (a.val == b.val && a.idx > b.idx);}    node(int val,int idx) : val(val) , idx(idx) {}
};priority_queue<node>qq;
int k , m , q , Time[maxn];
int v[maxn];
char ks[maxn][400];
dl tt[maxn];
int id[maxn];void initiation()
{scanf("%d%d%d",&k,&m,&q);for(int i = 1 ; i <= k ; ++ i) scanf("%s%d",ks[i],&v[i]);for(int i = 1 ; i <= m ; ++ i) scanf("%d%d",&tt[i].first,&tt[i].second);sort(tt + 1 , tt + 1 + m);for(int i = 1 ; i <= q; ++ i) scanf("%d",&id[i]);
}void solve()
{int ptr = 1;int cot = 0;int T = 1;for(int i = 1 ; i <= k ; ++ i){cot++;qq.push(node(v[i],i));while(ptr != m+1 && tt[ptr].first <= cot){int cv = tt[ptr].second;while(cv && !qq.empty()){node ss = qq.top();qq.pop();Time[T++] = ss.idx;cv--;}ptr++;}}while(!qq.empty()){node ss = qq.top();qq.pop();Time[T++] = ss.idx;}printf("%s",ks[Time[id[1]]]);for(int i = 2 ; i <= q ; ++ i) printf(" %s",ks[Time[id[i]]]);printf("\n");
}int main(int argc,char *argv[])
{int Case;scanf("%d",&Case);while(Case--){initiation();solve();}return 0;
}

转载于:https://www.cnblogs.com/qscqesze/p/4805247.html

hdu 5437 Alisha’s Party 优先队列相关推荐

  1. HDU OJ 5437 Alisha’s Party 2015online A

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

  2. 优先队列 HDOJ 5437 Alisha's Party

    题目传送门 题意:一人过生日,很多人排着队送礼物.排队顺序是礼物价值大的优先,如果相等先来的优先.有m次开门,当t个人到了会开门让p个人进门.最后一次让门外的所有人按顺序进门.有q次询问,问第x个进门 ...

  3. ACM学习历程—HDU 2112 HDU Today(map spfa 优先队列)

    Description 经过锦囊相助,海东集团终于度过了危机,从此,HDU的发展就一直顺风顺水,到了2050年,集团已经相当规模了,据说进入了钱江肉丝经济开发区500强.这时候,XHD夫妇也退居了二线 ...

  4. hdu 5040 Instrusive【BFS+优先队列】

    2014北京网络赛09题,hdu 5040 这次网络赛真是惨,也怪做题策略没想好,当时切完签到题之类的水题之后,马上就去看06青蛙那题去了.结果被那只死青蛙给坑惨了T_T...搞了四小时没搞出来... ...

  5. hdu 1254(dfs+bfs+优先队列)

    推箱子 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Problem Desc ...

  6. HDU Problem - 6396 Swordsman(优先队列,模拟)

    题目链接 Problem Description Lawson is a magic swordsman with kkk kinds of magic attributes v1,v2,v3,-,v ...

  7. HDU 1873 - 看病要排队 ← 优先队列

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=1873 [问题描述] 看病要排队这个是地球人都知道的常识. 不过经过细心的0068的观察,他发现了医 ...

  8. HDU 1434 幸福列车(优先队列)

    优先队列的应用 #include<iostream> #include<cstdio> #include<cstring> #include<queue> ...

  9. hdu.1254.推箱子(bfs + 优先队列)

    推箱子 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submis ...

  10. Hdu 1434 幸福列车【优先队列模拟】

    幸福列车 Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others) Total Submi ...

最新文章

  1. git多人协作冲突解决方法
  2. ACM入门之【分块习题】
  3. Javascript之全局变量和局部变量部分讲解
  4. Java并发教程–线程池
  5. vuex 在非组件中调用 mutations 方法
  6. 完美解决ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
  7. python中logging模块的一些简单用法
  8. php oracle 存储过程,用PHP调用Oracle存储过程
  9. mysql gis 高德_基于高德自定义地图数据的GIS矢量地图制作
  10. (亲测)使用cmd结束进程的3种方法
  11. php怎么画五星红旗,php基于GD库画五星红旗的方法,phpgd库五星红旗_PHP教程
  12. 通过VNC远程连接ubuntu桌面(多种客户端连接方式)
  13. 一山不容二虎?双动力同步驱动技术与模型分享
  14. FaceNet 读书笔记
  15. Java-Java基础—(6)面向对象高级
  16. ZOJ Yukari's Birthday
  17. 图的计算(1):图的矩阵表示
  18. 微信支付密码设置html,微信支付页面怎么加密码锁屏(微信支付界面怎么上锁)...
  19. VisualVM 使用心得
  20. 为什么要学习Java?|猿代码科技

热门文章

  1. python 特征选择卡方_4. 机器学习之特征选择-Python代码
  2. java 并发编程实战代码_「Java并发编程实战」对象的组合
  3. pytorch自带网络_一篇长文学懂 pytorch
  4. angularjs ng-include
  5. Android so文件进阶 一
  6. [置顶] java高级工程师-----struts的内部运行机制详解
  7. iOS 给测试人员测试手机APP的四种方法:真机运行(略),打ipa包,(testFlighe)邮件,蒲公英(二)testflight
  8. CodeForces-4C Registration system
  9. 《软件构架实践》阅读笔记4
  10. 移动端使用的WebKit私有属性(转)