Alisha’s Party (HDU5437)优先队列+模拟
Alisha 举办聚会,会在一定朋友到达时打开门,并允许相应数量的朋友进入,带的礼物价值大的先进,最后一个人到达之后放外面的所有人进来。用优先队列模拟即可。需要定义朋友结构体,存储每个人的到达顺序以及携带礼品价值,并重载<运算符。然后模拟即可。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
const int maxn = + ;
struct fri{
int v;int id;
friend bool operator < (const fri &a,const fri &b){
return a.v<b.v||(a.v==b.v&&a.id>b.id);
}
fri (int v,int id) :v(v),id(id){}
}; priority_queue <fri> pq;
char name[maxn][];
int v[maxn],id[maxn];
pair <int,int> tn[maxn];///开门时间及允许进入人数
int qe[maxn];
int tq[maxn]; int main(){
int t,k,m,q;
while(~scanf("%d",&t)){
while(t--){
scanf("%d%d%d",&k,&m,&q);
for(int i=;i<k;i++)
scanf("%s%d",name[i],&v[i]);
for(int i=;i<m;i++)
scanf("%d%d",&tn[i].first,&tn[i].second);
sort(tn,tn+m);
int pernum = ,cnt = ,T = ;
for(int i=;i<k;i++){
cnt++;
pq.push(fri(v[i],i));
while(pernum != m&& tn[pernum].first <= cnt){
int enternum = tn[pernum].second;
while(enternum && !pq.empty()){
fri ss = pq.top();pq.pop();
tq[T++] = ss.id;
enternum--;
}
pernum++;
}
}
while(!pq.empty()){
fri ss = pq.top();pq.pop();
tq[T++] = ss.id;
}
for(int i=;i<q;i++) {
scanf("%d",&qe[i]);
if(!i) printf("%s",name[tq[qe[i]-]]);
else printf(" %s",name[tq[qe[i]-]]);
}
printf("\n");
}
}
return ;
}
Alisha’s Party (HDU5437)优先队列+模拟的更多相关文章
- HDU 5437 Alisha’s Party (优先队列模拟)
题意:邀请k个朋友,每个朋友带有礼物价值不一,m次开门,每次开门让一定人数p(如果门外人数少于p,全都进去)进来,当最后所有人都到了还会再开一次门,让还没进来的人进来,每次都是礼物价值高的人先进.最后 ...
- hdu 5437(优先队列模拟)
Alisha’s Party Time Limit: 3000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) ...
- Codeforces Round #318 (Div. 2) A Bear and Elections (优先队列模拟,水题)
优先队列模拟一下就好. #include<bits/stdc++.h> using namespace std; priority_queue<int>q; int main( ...
- HDU5437 Alisha’s Party (优先队列 + 模拟)
Alisha’s Party Time Limit: 3000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) ...
- 优先队列 + 模拟 - HDU 5437 Alisha’s Party
Alisha’s Party Problem's Link Mean: Alisha过生日,有k个朋友来参加聚会,由于空间有限,Alisha每次开门只能让p个人进来,而且带的礼物价值越高就越先进入. ...
- HDU 5437 & ICPC 2015 Changchun Alisha's Party(优先队列)
Alisha’s Party Time Limit: 3000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) ...
- 暑假练习赛 004 E Joint Stacks(优先队列模拟)
Joint StacksCrawling in process... Crawling failed Time Limit:4000MS Memory Limit:65536KB 64 ...
- Codeforces Round #375 (Div. 2) Polycarp at the Radio 优先队列模拟题 + 贪心
http://codeforces.com/contest/723/problem/C 题目是给出一个序列 a[i]表示第i个歌曲是第a[i]个人演唱,现在选出前m个人,记b[j]表示第j个人演唱歌曲 ...
- Problem E: 穷游中国在统题 优先队列 + 模拟
http://www.gdutcode.sinaapp.com/problem.php?cid=1049&pid=4 Problem E: 穷游中国在统题 Description Travel ...
随机推荐
- How to find out which version of tensorflow is installed in my pc? - 如何找出我的电脑中安装了哪个版本的 tensorflow?
I'm using tensorflow and have got some weired issues. I'm told it might be related to the version of ...
- paramiko向服务器自动上传下载文件
import paramikoimport os def download_from(ip,u,p): file_list=['file2',file3','file4'] file_path=&qu ...
- R语言预测实战(游浩麟)笔记1
预测流程 确定主题.指标.主体.精度.周期.用户.成本和数据七要素. 收集数据.内容划分.收集原则. 选择方法.主要方法有自相关分析.偏相关分析.频谱分析.趋势分析.聚类分析.关联分析.相关分析.互相 ...
- 如何下载最新Xshell版本、免费官方正版软件的技巧过程
我们在操作和管理Linux VPS.服务器的时候,肯定需要使用SSH工具,对于这个工具网上有很多免费和付费版本.对于我们用户来说肯定会较多的选择免费软件.其中使用较多的还是Xshell工具,也是我认为 ...
- Oracle角色,权限,表空间基础语句
控制台: -sqlplus -----连接数据库 -conn sys/123456@orcl as sysdba -----登录sys -create tablespac ...
- python列表的学习笔记
列表的操作 第一个例子: #names = "zhangyang guyun xiangpeng xuliangchen" #通过空格或逗号存变量 names = [" ...
- Js的运算符
JS的运算符 1.运算符的分类: a) 算数运算符 b) 字符串运算符 c) 赋值运算符 d) 比较运算符 e) 逻辑运算符 f) 位运算符 g) 其他运算符 2.算数运算符 + 加法运算符 - 减法 ...
- java基础知识—类和对象
1.对象的特征---类的属性 每个对象的每个属性都有特定的值 对象的操作---类的方法 2.封装 对象同时具有属性和方法两项属性. 对象的属性和方法同时被封装在一起,共同体现事物的特性,二者相辅相成, ...
- input(Text)控件作为填空输入,但运行后,有曾经输入的记录显示,用autocomplete="off"解决
系统中,有设计填空题,原来程序中,用input(Text)控件, <input type="text" name="NO<%=rs("id&qu ...
- 服务集群session问题
1. http协议本身无状态,可通过Session与Cookie记录前端与后端服务器的交互状态: 2. 但是每次客户端回传必须在头信息中带有cookie, 如果session过多,会增加数据传输量: ...