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

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

Source

2015 ACM/ICPC Asia Regional Changchun Online

本来是一道简单的模拟题,我却花了很久的时间,一直wa,要跪了

后来还是请教了别人才知道错在哪里了

数据的时间是没有说是有序的,也就是时间的数据不一定是按照顺序给我们的。

所以要先对数据进行排序。

以后要时刻记住,输入数据一定要考虑乱序的情况。

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<queue>
 4 #include<algorithm>
 5
 6 #define pb push_back
 7
 8 using namespace std;
 9
10 const int maxn=150000+5;
11
12 struct Node
13 {
14     int v,id;
15     bool operator <(const Node&x)const
16     {
17         if(x.v==v)
18             return x.id<id;
19         return v<x.v;
20     }
21 };
22 struct Time
23 {
24     int tim,num;
25 };
26 Time time[maxn];
27 char name[maxn][205];
28 Node ord[maxn];
29 int ans[maxn];
30
31 bool cmp(Time x,Time y)
32 {
33     return x.tim<y.tim;
34 }
35
36 priority_queue<Node>que;
37
38 int main()
39 {
40     int test;
41     scanf("%d",&test);
42     while(test--){
43         int n,m,q;
44         scanf("%d %d %d",&n,&m,&q);
45         for(int i=0;i<n;i++){
46             scanf("%s %d",&name[i],&ord[i].v);
47             ord[i].id=i;
48         }
49
50         for(int i=0;i<m;i++){
51             scanf("%d %d",&time[i].tim,&time[i].num);
52         }
53
54         sort(time,time+m,cmp);
55
56         while(!que.empty())
57             que.pop();
58
59         int now=0,len=0;
60         for(int j=0;j<m;j++){
61             while(now<time[j].tim){
62                 que.push(ord[now]);
63                 now++;
64             }
65             while(time[j].num--){
66                 ans[len++]=que.top().id;
67                 que.pop();
68                 if(que.empty())
69                     break;
70             }
71         }
72         while(now<n){
73             que.push(ord[now++]);
74         }
75         while(!que.empty()){
76             ans[len++]=que.top().id;
77             que.pop();
78         }
79         int c;
80         for(int i=0;i<q-1;i++){
81             scanf("%d",&c);
82             printf("%s ",name[ans[c-1]]);
83         }
84         scanf("%d",&c);
85         printf("%s\n",name[ans[c-1]]);
86     }
87     return 0;
88 }

时间: 2024-10-27 12:37:40

hdu 5437 Alisha’s Party 模拟 优先队列的相关文章

Hdu 5437 Alisha’s Party(模拟)

题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=5437 思路:优先队列模拟,注意最后一次门外人全部进入. #include<cstdio> #include<queue> #include<cstring> #include<iostream> #include<algorithm> #define debu using namespace std; const int maxn=150000+50

hdu 5437 Alisha’s Party (优先队列)

http://acm.hdu.edu.cn/showproblem.php?pid=5437 题目意思比较好理解,如果暴力的话或超时,可以考虑到用优先队列就可以很简单的解决问题 1 #include<queue> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 using namespace std; 6 struct point { 7 int x,id; 8 char na[2

HDU 5437 Alisha’s Party

题目链接: http://acm.split.hdu.edu.cn/showproblem.php?pid=5437 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. Be

hdu 5437 Alisha’s Party (线段树)

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

HDU 5437 &amp; ICPC 2015 Changchun Alisha&#39;s Party(优先队列)

Alisha’s Party Time Limit: 3000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 7971    Accepted Submission(s): 1833 Description Princess Alisha invites her friends to come to her birthday party. Each of her f

Hdu 3887树状数组+模拟栈

题目链接 Counting Offspring Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1757    Accepted Submission(s): 582 Problem Description You are given a tree, it’s root is p, and the node is numbered fr

hdu 4891 The Great Pan(模拟)

题目链接:hdu 4891 The Great Pan 题目大意:给出一个文本,问说有多少种理解方式. 1. $$中间的,(s1+1) * (s2+1) * ...*(sn+1), si表示连续的空格数. 2.{}中间,即 | 的个数+1. 解题思路:模拟. #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int maxn = 1<<22

HDU 4930 Fighting the Landlords 模拟

_(:зゝ∠)_ 4带2居然不是炸弹,, #include <algorithm> #include <cctype> #include <cassert> #include <cstdio> #include <cstring> #include <climits> #include <vector> #include<iostream> using namespace std; #define N 18 #

hdu 3345 War Chess (bfs+优先队列)

War Chess Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1732    Accepted Submission(s): 416 Problem Description War chess is hh's favorite game: In this game, there is an N * M battle map, an