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. linux网卡掉包或挂掉解决办法

    最近自己公司网站老出现掉包问题之前以为是网络问题或机房问题,经过N久的排查发现是linux网卡掉包了,下面我来分享我的解决办法.   之前公司的系统由于网卡问题,经常出现掉包(掉包排除攻击的 因素)或 ...

  2. usb驱动开发篇简易介绍

    我这里重点的介绍如何写驱动程序,对于一些应用程序我就不做介绍了,因为我对于那些高层的东西写得很少.倘若再讲,有班门弄斧之嫌,呵呵! 作为WIN98和WIN2K推荐的一项新技术来说,USB的驱动程序和以 ...

  3. mysl lock table read

    <pre name="code" class="html">Session 1: mysql> use zjzc; Reading table ...

  4. poj 3661 Running(区间dp)

    Description The cows are trying to become better athletes, so Bessie ≤ N ≤ ,) minutes. During each m ...

  5. collectionView关于点击事件

    -(void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)i ...

  6. SqlServer之存储过程

    存储过程最主要的特色:是当写完一个存储过程后即被翻译成可执行码存储在系统表 内,当作是数据库的对象之一,一般用户只要执行存储过程,并且提供存储过程所需的参数就可以得到所要的结果而不必再去编辑 T-SQ ...

  7. 20个命令行工具监控 Linux 系统性能

    对于每个系统管理员或网络管理员来说,每天要监控和调试 Linux 系统性能问题都是非常困难的工作.我已经有5年 Linux 管理员的工作经历,知道如何监控系统使其保持正常运行.为此,我们编写了对于 L ...

  8. 浅谈JavaScript中的内存管理

    一门语言的内存存储方式是我们学习他必须要了解的,接下来让我浅谈一下自己对他的认识. 首先说,JavaScript中的变量包含两种两种类型: 1)值类型或基本类型:undefined.null.numb ...

  9. leetcode Longest Valid Parentheses python

    class Solution(object): def longestValidParentheses(self, s): """ :type s: str :rtype ...

  10. C++中的函数指针和指针函数

    C++中的函数指针和指针函数       数组名一般可以被当成指向数组第一个元素的常量指针,同样的情况,在函数中,函数名可以本当成指向函数的常量指针,假如一个函数已经定义,那么它在计算机中一定有特定的 ...