Alisha’s Party

Time Limit: 3000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 7514    Accepted Submission(s): 1748

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. Biis 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
 
Recommend
 
 
 
 #include <iostream>
#include <vector>
#include <cstdio>
#include <queue>
#include <cstring>
#include <cstdlib>
#include <algorithm>
using namespace std;
#define P pair<int,int>
#define ph push_back
#define ll long long
#define N 150009
#define fi first
#define se second
int t,n,m,q;
struct Ma{
string s;
int val,id;
bool operator <(const Ma&a)const{
if(val!=a.val)
return val<a.val;
return id>a.id;
}
}ma[N];
struct Node{
int time,p;
}nod[N];
bool cmp(Node a,Node b)
{
return a.time<b.time;
}
string ret[N];
char ss[];
int main()
{
scanf("%d",&t);
while(t--)
{
scanf("%d%d%d",&n,&m,&q);
for(int i=;i<=n;i++)
{
scanf("%s%d",ss,&ma[i].val);
ma[i].s=ss;
ma[i].id=i;
}
for(int i=;i<m;i++)
{
scanf("%d%d",&nod[i].time,&nod[i].p);
}
sort(nod,nod+m,cmp);
priority_queue<Ma>que;
int pos=,cnt=;
for(int i=;i<m;i++)
{
while(pos<=nod[i].time){
que.push(ma[pos]);//pos容易写错
pos++;
}
for(int j=;j<nod[i].p;j++)
{
if(que.empty()) break;//小于p个人,都进去
Ma x=que.top();que.pop();
ret[cnt++]=x.s;
}
}
while(pos<=n)
{
que.push(ma[pos]);
pos++;
}
while(!que.empty()){
Ma x=que.top();que.pop();
ret[cnt++]=x.s;
}
int y;
for(int l=;l<q;l++)
{
scanf("%d",&y);
printf("%s%c",ret[y].c_str(),l==q-?'\n':' ');
}
}
return ;
}

hdu 5437的更多相关文章

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

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

  2. hdu 5437 优先队列+模拟 **

    比赛的时候虽然考虑到没门的情况,但是写了几组都能过,就没想了,23333,差一行代码就能A,遗憾~~ #include<cstdio> #include<iostream> # ...

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

    Problem Description Princess Alisha invites her friends to come to her birthday party. Each of her f ...

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

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

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

  6. HDU 5437 Alisha’s Party

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

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

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

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

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

  9. HDU 5437 & ICPC 2015 Changchun Alisha's Party(优先队列)

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

随机推荐

  1. Codeforces Round #542(Div. 2) A.Be Positive

    链接:https://codeforces.com/contest/1130/problem/A 题意: 给n个数,找出一个非0整数d,使所有n个数除以整数d后,数组中正数的数量>= n/2. ...

  2. Codeforces Round #390 (Div. 2) D

    All our characters have hobbies. The same is true for Fedor. He enjoys shopping in the neighboring s ...

  3. Spark Mllib里如何将trainDara训练数据文件里提取第M到第N字段(图文详解)

    不多说,直接上干货! 具体,见 Hadoop+Spark大数据巨量分析与机器学习整合开发实战的第13章 使用决策树二元分类算法来预测分类StumbleUpon数据集

  4. 基于Java实现的插入排序算法

    简述 插入排序(Insertion-Sort)的算法描述是一种简单直观的排序算法.它的工作原理是通过构建有序序列,对于未排序数据,在已排序序列中从后向前扫描,找到相应位置并插入.插入排序在实现上,通常 ...

  5. mysql查询问题

    需求:根据选择不同的分类id,查找到同时属于选中的分类的文章id sql语句: select result,GROUP_CONCAT(category_id) from (select categor ...

  6. github入门之创建仓库--3

    1.登陆到github,点击加号中的New repository 2.设置仓库信息 *注: ------Description:添加仓库说明,不是必填项 ------Public.Private:选择 ...

  7. [jQuery] Cannot read property ‘msie’ of undefined错误的解决方法 --转

    初用Yii的srbac模块.出现 Cannot read property ‘msie’ of undefined 错误.上网查询,找到如下的文章.使用文末的打补丁的方法,成功搞定.感谢. ===== ...

  8. LeetCode 3Sum Closest 最近似的3sum(2sum方法)

    题意:找到最接近target的3个元素之和,并返回该和. 思路:用2个指针,时间复杂度O(n^2). int threeSumClosest(vector<int>& nums, ...

  9. 使用office 365打开excel文件报错,提示“向程序发送命令时出现问题”

    我买了一套正版的office 365装在我的windows10 上.但是每次打开excel都会报错,如图一.求教了微软技术人员,他们给出了以下办法: 图一 方法一: 修复安装Office ====== ...

  10. java 核心技术卷一笔记 6 .1接口 lambda 表达式 内部类

    6.1 接口不是类,是对类的一组需求的描述,这些类需要遵守接口描述的统一格式进行定义.例如:Arrays类中sort方法(可以对对象数组进行排序)前提是对象所属的类必须实现了Comparable 接口 ...