Alisha’s Party

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

Problem Description
Princess Alisha invites her friends to come to her birthday party. Each of her friends will bring a gift of some valuev, 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 queryn 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
题解;交了20多遍。。。。
有许多人带有权值的礼物来拜访公主,公主会在第ti个人到的时候把门打开瞬间,放ki个人进来,其中进来的顺序是权值最大的先进,如果权值一样大就先来的先进。当人全部到齐后会再次开门让所有人都进来。
两个代码:
 #include<stdio.h>
#include<string.h>
#include<queue>
#define ini(x) while(!x.empty())x.pop()
using namespace std;
const int MAXN=;
struct Node{
char s[];
int w,n;
friend bool operator < (Node a,Node b){
if(a.w!=b.w)return a.w<b.w;
else return a.n>b.n;
}
};
priority_queue<Node>dl;
queue<Node>as;
queue<Node>ae;
struct open{
int k,n;
friend bool operator < (open a,open b){
return a.k>b.k;
}
};
priority_queue<open>op;
char ans[MAXN][];
int main(){
int T,k,m,q;
scanf("%d",&T);
while(T--){
ini(as);ini(ae);ini(op);
scanf("%d%d%d",&k,&m,&q);
Node a;
for(int i=;i<=k;i++){
scanf("%s%d",a.s,&a.w);
a.n=i;
as.push(a);
}
open b;
for(int i=;i<=m;i++){
scanf("%d%d",&b.k,&b.n);
op.push(b);
}b=op.top();
for(int i=;i<=k;i++){
a=as.front();
as.pop();
dl.push(a);
if(op.empty())continue;//错到这里了
if(i==b.k){
int t=;
while(t++<b.n){
if(dl.empty())break;
a=dl.top();
dl.pop();
ae.push(a);
}
op.pop();b=op.top();
}
}
while(!dl.empty()){
a=dl.top();
dl.pop();
ae.push(a);
}
int k=;
while(!ae.empty()){
a=ae.front();ae.pop();
strcpy(ans[k++],a.s);
}
int x;
for(int i=;i<q;i++){
scanf("%d",&x);
if(i)printf(" ");
printf("%s",ans[x]);
}
puts("");
}
return ;
}

代码二:

 #include<stdio.h>
#include<string.h>
#include<queue>
#include<algorithm>
#define ini(x) while(!x.empty())x.pop()
using namespace std;
const int MAXN=;
struct Node{
char s[];
int w,n;
friend bool operator < (Node a,Node b){
if(a.w!=b.w)return a.w<b.w;
else return a.n>b.n;
}
};
priority_queue<Node>dl;
Node as[MAXN];
queue<Node>ae;
struct open{
int k,n;
};
open op[MAXN];
int cmp(open a,open b){
if(a.k!=b.k)return a.k<b.k;
else return a.n>b.n;
}
char ans[MAXN][];
int main(){
int T,k,m,q;
scanf("%d",&T);
while(T--){
ini(ae);ini(dl);
scanf("%d%d%d",&k,&m,&q);
Node a;
for(int i=;i<=k;i++){
scanf("%s%d",a.s,&a.w);
a.n=i;
as[i]=a;
}
open b;
for(int i=;i<=m;i++){
scanf("%d%d",&b.k,&b.n);
op[i]=b;
}
sort(op+,op+m+,cmp);
for(int i=,j=;i<=k;i++){
a=as[i];
dl.push(a);
if(j>m)continue;//错到这里了
if(i==op[j].k){
int t=;
while(t++<op[j].n){
if(dl.empty())break;
a=dl.top();
dl.pop();
ae.push(a);
}
j++;
}
}
while(!dl.empty()){
a=dl.top();
dl.pop();
ae.push(a);
}
int k=;
while(!ae.empty()){
a=ae.front();ae.pop();
strcpy(ans[k++],a.s);
}
int x;
for(int i=;i<q;i++){
scanf("%d",&x);
if(i)printf(" ");
printf("%s",ans[x]);
}
puts("");
}
return ;
}

代码三:

 #include<stdio.h>
#include<string.h>
#include<algorithm>
#include<queue>
using namespace std;
const int MAXN=;
struct Node{
char s[];
int w;
int nm;
};
bool operator < (Node a,Node b){
if(a.w!=b.w)return a.w<b.w;
else return a.nm>b.nm;
}
struct Peo{
int gate,num;
}door[MAXN];
Node man[MAXN];
int cmp(Peo a,Peo b){
return a.gate<b.gate;
}
struct ANS{
char s[];
};
ANS ans[MAXN];
/*void print(int i,int q){
int x;
if(i>q)return;
scanf("%d",&x);
print(i+1,q);
printf("%s",ans[x]);
if(i!=q)printf(" ");
}*/
int main(){
int T,k,m,q;
scanf("%d",&T);
while(T--){
// memset(ans,0,sizeof(ans));
// memset(door,0,sizeof(door));
priority_queue<Node>dl;
queue<Node>as;
scanf("%d%d%d",&k,&m,&q);
for(int i=;i<=k;i++)
scanf("%s%d",man[i].s,&man[i].w),man[i].nm=i;
for(int i=;i<=m;i++)scanf("%d%d",&door[i].gate,&door[i].num);
sort(door+,door+m+,cmp);
for(int i=,j=;i<=k;i++){
//if(!dl.empty())printf("%s\n",dl.top().s);
dl.push(man[i]);
if(j>m)continue;
//if(!dl.empty())printf("%s\n",dl.top().s);
if(i==door[j].gate){
int t=;
while(t<door[j].num){
// printf("%d\n",door[j].num);
if(dl.empty())break;
Node a=dl.top();
as.push(a);
//if(!dl.empty())printf("%d %s\n",t,a.s);
dl.pop();
t++;
}
j++;
} }
// for(int i=1;i<=k;i++)printf("%s ",dl.top().s),dl.pop();
// puts("");
//for(int i=1;i<=k;i++)printf("%s ",as.front().s),as.pop();
while(!dl.empty()){
as.push(dl.top());
dl.pop();
}
int x=;
while(!as.empty()){
Node a;
a=as.front();
as.pop();
strcpy(ans[x].s,a.s);
x++;
}
//print(1,q);
for(int i=;i<=q;i++){
scanf("%d",&x);
if(i!=)printf(" ");
printf("%s",ans[x].s);
}
puts("");
}
return ;
}
 

Alisha’s Party(队列)的更多相关文章

  1. 消息队列——RabbitMQ学习笔记

    消息队列--RabbitMQ学习笔记 1. 写在前面 昨天简单学习了一个消息队列项目--RabbitMQ,今天趁热打铁,将学到的东西记录下来. 学习的资料主要是官网给出的6个基本的消息发送/接收模型, ...

  2. 消息队列 Kafka 的基本知识及 .NET Core 客户端

    前言 最新项目中要用到消息队列来做消息的传输,之所以选着 Kafka 是因为要配合其他 java 项目中,所以就对 Kafka 了解了一下,也算是做个笔记吧. 本篇不谈论 Kafka 和其他的一些消息 ...

  3. Beanstalkd一个高性能分布式内存队列系统

    高性能离不开异步,异步离不开队列,内部是Producer-Consumer模型的原理. 设计中的核心概念: job:一个需要异步处理的任务,是beanstalkd中得基本单元,需要放在一个tube中: ...

  4. .net 分布式架构之业务消息队列

    开源QQ群: .net 开源基础服务  238543768 开源地址: http://git.oschina.net/chejiangyi/Dyd.BusinessMQ ## 业务消息队列 ##业务消 ...

  5. 【原创经验分享】WCF之消息队列

    最近都在鼓捣这个WCF,因为看到说WCF比WebService功能要强大许多,另外也看了一些公司的招聘信息,貌似一些中.高级的程序员招聘,都有提及到WCF这一块,所以,自己也关心关心一下,虽然目前工作 ...

  6. 缓存、队列(Memcached、redis、RabbitMQ)

    本章内容: Memcached 简介.安装.使用 Python 操作 Memcached 天生支持集群 redis 简介.安装.使用.实例 Python 操作 Redis String.Hash.Li ...

  7. Java消息队列--ActiveMq 实战

    1.下载安装ActiveMQ ActiveMQ官网下载地址:http://activemq.apache.org/download.html ActiveMQ 提供了Windows 和Linux.Un ...

  8. Java消息队列--JMS概述

    1.什么是JMS JMS即Java消息服务(Java Message Service)应用程序接口,是一个Java平台中关于面向消息中间件(MOM)的API,用于在两个应用程序之间,或分布式系统中发送 ...

  9. 消息队列性能对比——ActiveMQ、RabbitMQ与ZeroMQ(译文)

    Dissecting Message Queues 概述: 我花了一些时间解剖各种库执行分布式消息.在这个分析中,我看了几个不同的方面,包括API特性,易于部署和维护,以及性能质量..消息队列已经被分 ...

随机推荐

  1. 5款免费Windows远程连接Linux桌面软件(VNC客户端)

        不论我们出于何种的用途目的,很多朋友有需要用到VNC链接Linux桌面环境,之前老左有分享过VNC Viewer绿色软件,昨天有朋友提出来使用之后登录远程桌面的界面.分辨率等有些色差.流畅程度 ...

  2. eclipse中调出android sdk manager和android virtual device manager图标

    有时候在安装ADT插件后,eclipse菜单栏上不会显示android sdk manager和android virtual device manager两个图标, 这个时候,如果安装ADT插件的步 ...

  3. ArcGIS学习推荐基础教程摘录

    ###########-------------------摘录一--------------------------########### ***************************** ...

  4. aix lvm_lv_vg

    Aix扩展文件系统,添加新硬盘 Cfgmgr 重新扫描新硬盘 Lspv Chdev –l hdisk3 –a pv=yes Extendvg rootvg hdisk3 note 上面的报错解决 Sm ...

  5. http multipart/form-data POST文件上传详解

    POST /test/index.php HTTP/1.1 User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:26.0) Gecko/20100101 Firef ...

  6. HDOJ 2689

    Sort it Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Su ...

  7. Thrift使用实例

    首先下载thrift.exe,和对应lib包.注意版本一定要一致. 否则编译会不识别出现错误. 可能会出现org.slf4j这个错误,那么你要把slf4j-api.jar下载下来引入到你的projec ...

  8. globalCompositeOperation 学习

    globalCompositeOperation globalCompositeOperation即Canvas中的合成操作. 1.source-over 这是默认值,他表示绘制的图形将画在现有画布之 ...

  9. SharePoint 2013设置“以其他用户身份登录”

    登录web服务器,打开位于“C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\TEMPLATE\CONTR ...

  10. EBS R12 怎么修改APPS密码

    apps 和 applsys 的口令 $> FNDCPASS apps/<apps password> 0 Y system/<system password> SYST ...