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 ...
随机推荐
- c语言中,在结构体中如何将void *转存为具体需要的数据类型
1. 只需要将该void *类型成员,强制转换为具体的数据类型指针即可.需要注意的是,该强制转换是有风险的,转换时,必须确定void*指向内存实际数据为目标结构体格式,否则可能会出现内存越界访问,从而 ...
- HTML、CSS(小笔记)
这是我自己在学习html.css时觉得要记的东西太多总结一些较为常用的标签. HTML <p></p>段落标签 <hn></hn>标题标签n数值为1~6 ...
- python之路-变量
变量定义的规则: - 变量名只能是字母.数字.或下划线的任意组合 - 变量名的第一个字符不能是数字 - 以下关键字不能声明为变量名 ['and','as','assert','break','cla ...
- Python随笔--魔法方法(析构与构造)
#析构方法的调用
- react native第一天--------KnightRider
今天是2017年6月8,是我的项目react native-CRM(用户关系管理)的第一天,一早就配置了一上午Mac的环境,然后运行项目,在react-native init project的时候一直 ...
- solrcloud jsonfacet分组聚合 unique计数不准确
jsonfacet分组聚合查询 unique.hll函数问题: 对不同的值进行估算,并非准确的值, 优点:节省内存消耗,用分组算法对不同的值count进行估算 缺点:无法准确统计count(disti ...
- react native进一步学习(NavigatorIOS 学习)
特别申明:本人代码不作为任何商业的用途,只是个人学习的一些心得,为了使得后来的更多的程序员少走一些弯路.*(如若侵犯你的版权还望见谅)*. 开发工具:WebStorm,xcode 1. rn的创建的时 ...
- SSL backend error when using OpenSSL pycurl install error
centos7 pip install pycurl 错误 pip uninstall pycurl export PYCURL_SSL_LIBRARY=nss pip install pycurl ...
- django框架中form组件的简单使用示例:注册验证
Django中form组件的三大特点: 1. 生成页面可使用的HTML标签 2. 对用户提交的数据进行初步校验 3. 保留上次输入内容 废话不多说,直接进入正题. 这是注册界面截图: 与上一篇a ...
- Educational Codeforces Round 63 (Rated for Div. 2) D. Beautiful Array (简单DP)
题目:https://codeforces.com/contest/1155/problem/D 题意:给你n,x,一个n个数的序列,你可以选择一段区间,区间的数都乘以x,然后求出最大字段和 思路: ...