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

时间:2021-08-01 11:52:42
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
 
 
 
 
本来是一道简单的模拟题,我却花了很久的时间,一直wa,要跪了
后来还是请教了别人才知道错在哪里了
数据的时间是没有说是有序的,也就是时间的数据不一定是按照顺序给我们的。
所以要先对数据进行排序。
 
以后要时刻记住,输入数据一定要考虑乱序的情况。
 
 
 #include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm> #define pb push_back using namespace std; const int maxn=+; struct Node
{
int v,id;
bool operator <(const Node&x)const
{
if(x.v==v)
return x.id<id;
return v<x.v;
}
};
struct Time
{
int tim,num;
};
Time time[maxn];
char name[maxn][];
Node ord[maxn];
int ans[maxn]; bool cmp(Time x,Time y)
{
return x.tim<y.tim;
} priority_queue<Node>que; int main()
{
int test;
scanf("%d",&test);
while(test--){
int n,m,q;
scanf("%d %d %d",&n,&m,&q);
for(int i=;i<n;i++){
scanf("%s %d",&name[i],&ord[i].v);
ord[i].id=i;
} for(int i=;i<m;i++){
scanf("%d %d",&time[i].tim,&time[i].num);
} sort(time,time+m,cmp); while(!que.empty())
que.pop(); int now=,len=;
for(int j=;j<m;j++){
while(now<time[j].tim){
que.push(ord[now]);
now++;
}
while(time[j].num--){
ans[len++]=que.top().id;
que.pop();
if(que.empty())
break;
}
}
while(now<n){
que.push(ord[now++]);
}
while(!que.empty()){
ans[len++]=que.top().id;
que.pop();
}
int c;
for(int i=;i<q-;i++){
scanf("%d",&c);
printf("%s ",name[ans[c-]]);
}
scanf("%d",&c);
printf("%s\n",name[ans[c-]]);
}
return ;
}
 
 
 
 
 
 
 
 
 
 
 

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

  1. HDU 5437 Alisha’s Party (优先队列模拟)

    题意:邀请k个朋友,每个朋友带有礼物价值不一,m次开门,每次开门让一定人数p(如果门外人数少于p,全都进去)进来,当最后所有人都到了还会再开一次门,让还没进来的人进来,每次都是礼物价值高的人先进.最后 ...

  2. 优先队列 &plus; 模拟 - HDU 5437 Alisha’s Party

    Alisha’s Party Problem's Link Mean: Alisha过生日,有k个朋友来参加聚会,由于空间有限,Alisha每次开门只能让p个人进来,而且带的礼物价值越高就越先进入. ...

  3. hdu 5437 Alisha’s Party 优先队列

    Alisha’s Party Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/contests/contest_sh ...

  4. HDU 5437 Alisha’s Party &lpar;优先队列&rpar;——2015 ACM&sol;ICPC Asia Regional Changchun Online

    Problem Description Princess Alisha invites her friends to come to her birthday party. Each of her f ...

  5. HDU 1103 Flo's Restaurant&lpar;模拟&plus;优先队列&rpar;

    Flo's Restaurant Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  6. HDU 5437 Alisha’s Party

    题意:有k个人带着价值vi的礼物来,开m次门,每次在有t个人来的时候开门放进来p个人,所有人都来了之后再开一次门把剩下的人都放进来,每次带礼物价值高的人先进,价值相同先来先进,q次询问,询问第n个进来 ...

  7. HDU 4041 Eliminate Witches&excl; (模拟题 ACM ICPC 2011亚洲北京赛区网络赛)

    HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011 亚洲北京赛区网络赛题目) Eliminate Witches! Time Limit: 2000/1000 ...

  8. hdu6136&lbrack;模拟&plus;优先队列&rsqb; 2017多校8

    有点麻烦.. /*hdu6136[模拟+优先队列] 2017多校8*/ #include <bits/stdc++.h> using namespace std; typedef long ...

  9. hdu 5437&lpar;优先队列模拟&rpar;

    Alisha’s Party Time Limit: 3000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) ...

随机推荐

  1. SVN冲突解决:当次提交的和上次提交的出现冲突

    转载于知蚁博客,文章地址:http://www.letuknowit.com/archives/svn-conflict-resolution 看到那个*了吧,出现这个标记就说明本地副本的文件已经过期 ...

  2. Web---Cookie技术&lpar;显示用户上次登录的时间、显示用户最近浏览的若干个图片&lpar;按比例缩放&rpar;&rpar;

    本章博客讲解: 1.Cookie基本用法演示 2.演示Cookie的访问权限 3.演示Cookie的删除 4.利用Cookie显示用户上次登录的时间 5.利用Cookie技术显示用户最近浏览的若干个图 ...

  3. 贪心算法——Fence Repair&lpar;POJ 3253&rpar;

    题目描述 农夫约翰为了修理栅栏,要将一块很长的木板切割成N块.准备切成的木板长度为L1,L2,L3--LN,未切割前木板的长度恰好为切割后木板长度的总和.每次切断木板时,需要的开销为这块木板的长度.请 ...

  4. Centos&sol;Rhel7部署Zabbix监控(部署篇之服务器篇)

    Zabbix是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案. Zabbix能监视各种网络参数,保证服务器系统的安全运营:并提供灵活的通知机制以让系统管理员快速定位/解决 ...

  5. WCF Restful调用跨域解决方案

    目前很多项目中CRM更多扮演一个纯后台管理系统,用户更多的操作是在移动端执行,不管是安卓还是IOS甚至是H5.这里以H5为例,CRM提供数据接口,移动web端来调用接口进行数据处理,这里就会涉及到一个 ...

  6. Mybatis解决jdbc编程的问题

    1.1.1  Mybatis解决jdbc编程的问题 1.  数据库链接创建.释放频繁造成系统资源浪费从而影响系统性能,如果使用数据库链接池可解决此问题. 解决:在SqlMapConfig.xml中配置 ...

  7. Ubuntu16&period;04重新安装MySQL数据库

    安装之前先检查mysql是否卸载干净 dpkg --list|grep mysql 如果没有卸载干净请看上篇文章将mysql卸载干净 Ubuntu16.04彻底卸载MySQL 开始安装 可以直接默认安 ...

  8. Webpack&plus;Vue&plus;ES6 前端组件化开发mobile-multi-page应用实战总结和踩坑

    本文版权归博客园和作者吴双本人共同所有 转载和爬虫请注明原文地址 www.cnblogs.com/tdws 一.写在前面 项目上线有一段时间了,一个基于webpack+vue+ES6的手机端多页面应用 ...

  9. 【PMP】项目和运营的区别

    运营管理关注产品的持续性生产和服务的持续运作. 项目与运营会存在产品生命周期的不同时点交叉,例如: 在产品开发.产品升级或提高产量时: 在改进运营或产品开发流程时: 在产品生命周期结束阶段: 在每个收 ...

  10. Excel vba map&sol;dictionary

    今天在调整一生成java代码的工具时,要用到在不同语言间互转数据类型的逻辑,原来的代码中根据excel记录的行号来计算,再到另外一个collection中获取,个人想着这也太土鳖了,于是搜了下,在vb ...