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

本文探讨如何通过排序和模拟方法解决公主Alisha邀请朋友参加生日派对的问题,重点在于如何根据礼物的价值让朋友们有序进入城堡,并在特定时间允许一定数量的人进入。文章详细解释了输入输出格式、数据处理步骤以及解决问题的关键算法,帮助读者理解并应用到类似场景中。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

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 nth person to enter her castle is.
 

 

Input
The first line of the input gives the number of test cases, T , where 1T15.

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 1k150,000. The door would open m times before all Alisha’s friends arrive where 0mk. Alisha will have q queries where 1q100.

The ith of the following k lines gives a string Bi, which consists of no more than 200 English characters, and an integer vi1vi108, separated by a blank.Bi is the name of the ith person coming to Alisha’s party and Bi brings a gift of value vi.

Each of the following m lines contains two integers t(1tk) and p(0pk) separated by a blank. The door will open right after the tth 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 n1th,...,nqth 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
 
 
 
 
本来是一道简单的模拟题,我却花了很久的时间,一直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 }
View Code

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 
 
 
 
 
 
 
 
 
 
 

转载于:https://www.cnblogs.com/-maybe/p/4805493.html

资源下载链接为: https://pan.quark.cn/s/22ca96b7bd39 在当今的软件开发领域,自动化构建与发布是提升开发效率和项目质量的关键环节。Jenkins Pipeline作为一种强大的自动化工具,能够有效助力Java项目的快速构建、测试及部署。本文将详细介绍如何利用Jenkins Pipeline实现Java项目的自动化构建与发布。 Jenkins Pipeline简介 Jenkins Pipeline是运行在Jenkins上的一套工作流框架,它将原本分散在单个或多个节点上独立运行的任务串联起来,实现复杂流程的编排与可视化。它是Jenkins 2.X的核心特性之一,推动了Jenkins从持续集成(CI)向持续交付(CD)及DevOps的转变。 创建Pipeline项目 要使用Jenkins Pipeline自动化构建发布Java项目,首先需要创建Pipeline项目。具体步骤如下: 登录Jenkins,点击“新建项”,选择“Pipeline”。 输入项目名称和描述,点击“确定”。 在Pipeline脚本中定义项目字典、发版脚本和预发布脚本。 编写Pipeline脚本 Pipeline脚本是Jenkins Pipeline的核心,用于定义自动化构建和发布的流程。以下是一个简单的Pipeline脚本示例: 在上述脚本中,定义了四个阶段:Checkout、Build、Push package和Deploy/Rollback。每个阶段都可以根据实际需求进行配置和调整。 通过Jenkins Pipeline自动化构建发布Java项目,可以显著提升开发效率和项目质量。借助Pipeline,我们能够轻松实现自动化构建、测试和部署,从而提高项目的整体质量和可靠性。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值