Alisha’s Party(队列)

时间:2024-01-02 10:58:44

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 valuevAlisha’s Party(队列), 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 pAlisha’s Party(队列) people enter her castle. If there are less than pAlisha’s Party(队列) 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 querynAlisha’s Party(队列) Please tell Alisha who the n−thAlisha’s Party(队列) person to enter her castle is.

Input
The first line of the input gives the number of test cases,TAlisha’s Party(队列) , where 1≤T≤15Alisha’s Party(队列).

In each test case, the first line contains three numbers k,mAlisha’s Party(队列) and qAlisha’s Party(队列) separated by blanks. kAlisha’s Party(队列) is the number of her friends invited where 1≤k≤150,000Alisha’s Party(队列). The door would open m times before all Alisha’s friends arrive where 0≤m≤kAlisha’s Party(队列). Alisha will have qAlisha’s Party(队列) queries where 1≤q≤100Alisha’s Party(队列).

The i−thAlisha’s Party(队列) of the following kAlisha’s Party(队列) lines gives a string BAlisha’s Party(队列)iAlisha’s Party(队列)Alisha’s Party(队列), which consists of no more than 200Alisha’s Party(队列) English characters, and an integer vAlisha’s Party(队列)iAlisha’s Party(队列)Alisha’s Party(队列),1≤vAlisha’s Party(队列)iAlisha’s Party(队列)≤10Alisha’s Party(队列)8Alisha’s Party(队列)Alisha’s Party(队列), separated by a blank. BAlisha’s Party(队列)iAlisha’s Party(队列)Alisha’s Party(队列) is the name of the i−thAlisha’s Party(队列) person coming to Alisha’s party and Bi brings a gift of value vAlisha’s Party(队列)iAlisha’s Party(队列)Alisha’s Party(队列).

Each of the following mAlisha’s Party(队列) lines contains two integers t(1≤t≤k)Alisha’s Party(队列) and p(0≤p≤k)Alisha’s Party(队列) separated by a blank. The door will open right after the t−thAlisha’s Party(队列) person arrives, and Alisha will let pAlisha’s Party(队列) friends enter her castle.

The last line of each test case will contain qAlisha’s Party(队列) numbers nAlisha’s Party(队列)1Alisha’s Party(队列),...,nAlisha’s Party(队列)qAlisha’s Party(队列)Alisha’s Party(队列) separated by a space, which means Alisha wants to know who are the nAlisha’s Party(队列)1Alisha’s Party(队列)−th,...,nAlisha’s Party(队列)qAlisha’s Party(队列)−thAlisha’s Party(队列) friends to enter her castle.

Note: there will be at most two test cases containing n>10000Alisha’s Party(队列).

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 ;
}