HDU 5437 Alisha’s Party (优先队列模拟)
题意:邀请k个朋友,每个朋友带有礼物价值不一,m次开门,每次开门让一定人数p(如果门外人数少于p,全都进去)进来,当最后所有人都到了还会再开一次门,让还没进来的人进来,每次都是礼物价值高的人先进。最后给出q个数,表示要输出第ni个进来的人的名字。
析:其实这就是一个模拟题,很容易知道是优先队列模拟,不能set,会超时,反正我是超时了,然后就一步步的模拟就好了,注意它给的时间可能不是按顺序,要排序,在比赛时我就没排序,一直WA。。。。
代码如下:
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
using namespace std ;
typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f3f;
const double eps = 1e-8;
const int maxn = 150000 + 5;
const int dr[] = {0, 0, -1, 1};
const int dc[] = {-1, 1, 0, 0};
int n, m;
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
}
struct node{
int id, val;
char name[205];
bool operator < (const node &p) const{
return val < p.val || (val == p.val && id > p.id);
}
};
node a[maxn];
P pt[maxn];
int id[maxn];
int ans[maxn];
priority_queue<node> pq; int main(){
// ios::sync_with_stdio(false);
int T, q; cin >> T;
while(T--){
scanf("%d %d %d", &n, &m, &q);
for(int i = 0; i < n; ++i){
scanf("%s %d", a[i].name, &a[i].val);
a[i].id = i;
}
for(int i = 0; i < m; ++i)
scanf("%d %d", &pt[i].first, &pt[i].second);
sort(pt, pt+m);
pt[m].first = pt[m].second = 0;
for(int i = 0; i < q; ++i) scanf("%d", &id[i]);
int cnt = 0;
for(int i = 0, j = 0; i < n; ++i){
pq.push(a[i]);
if(i + 1 == pt[j].first){
int x = 0;
while(!pq.empty() && x < pt[j].second){
ans[cnt++] = pq.top().id;
pq.pop();
++x;
}
++j;
}
} while(!pq.empty()){
ans[cnt++] = pq.top().id;
pq.pop();
} for(int i = 0; i < q; ++i){
if(i) putchar(' ');
printf("%s", a[ans[id[i]-1]].name);
}
printf("\n");
} return 0;
}
HDU 5437 Alisha’s Party (优先队列模拟)的更多相关文章
- hdu 5437 Alisha’s Party 优先队列
Alisha’s Party Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/contests/contest_sh ...
- HDU 5437 Alisha’s Party (优先队列)——2015 ACM/ICPC Asia Regional Changchun Online
Problem Description Princess Alisha invites her friends to come to her birthday party. Each of her f ...
- hdu 5437 Alisha’s Party 模拟 优先队列
Problem Description Princess Alisha invites her friends to come to her birthday party. Each of her f ...
- 优先队列 + 模拟 - HDU 5437 Alisha’s Party
Alisha’s Party Problem's Link Mean: Alisha过生日,有k个朋友来参加聚会,由于空间有限,Alisha每次开门只能让p个人进来,而且带的礼物价值越高就越先进入. ...
- HDU 5437 Alisha’s Party
题意:有k个人带着价值vi的礼物来,开m次门,每次在有t个人来的时候开门放进来p个人,所有人都来了之后再开一次门把剩下的人都放进来,每次带礼物价值高的人先进,价值相同先来先进,q次询问,询问第n个进来 ...
- 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 Time Limit: 3000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) ...
- Alisha’s Party (HDU5437)优先队列+模拟
Alisha 举办聚会,会在一定朋友到达时打开门,并允许相应数量的朋友进入,带的礼物价值大的先进,最后一个人到达之后放外面的所有人进来.用优先队列模拟即可.需要定义朋友结构体,存储每个人的到达顺序以及 ...
- HDU 1428 漫步校园 (BFS+优先队列+记忆化搜索)
题目地址:HDU 1428 先用BFS+优先队列求出全部点到机房的最短距离.然后用记忆化搜索去搜. 代码例如以下: #include <iostream> #include <str ...
随机推荐
- get 与post 的接收传值方式
1.get方法接收值写法 string ad = Request["name"]; 2.post方法接收值写法 <%string a = Request.Form[" ...
- memcached的LRU删除机制
1)memcached不会自动清空缓存的值如果add了一个值,但不去get它,那么这个值过期了,它也不会被清空.解释:memcached不自动检测和清空值,它只当你需要get这个值的时候,才检测这个值 ...
- POJ 1201 Intervals (差分约束系统)
题意 在区间[0,50000]上有一些整点,并且满足n个约束条件:在区间[ui, vi]上至少有ci个整点,问区间[0, 50000]上至少要有几个整点. 思路 差分约束求最小值.把不等式都转换为&g ...
- jquery validate如何不提交表单就做验证(ajax提交数据)
if($("#FromID").valid()){ $.ajax({ type:'post', url:'/CampaignOrderRelations/save', data:{ ...
- Apache加载PHP.ini顺序
网上找到一份关于Apache加载PHP.ini顺序的文档: (1) apache的httpd.conf中的PhpIniDir: (2) 注册表键值:HKEY_LOCAL_MACHINE->SOF ...
- rtree
https://zh.wikipedia.org/wiki/R%E6%A0%91 http://blog.csdn.net/jiqiren007/article/details/5377750 htt ...
- [转] 接触C# 反射 2
逆心 原文 反射基础,2013-4. 反射用于在程序运行过程中,获取类里面的信息或发现程序集并运行的一个过程.通过反射可以获得.dll和.exe后缀的程序集里面的信息.使用反射可以看到一个程序集内部的 ...
- ADO.NET+Access: 2,至少一个参数没有被指定值
ylbtech-Error-ADO.NET+Access: 2,至少一个参数没有被指定值. 1.A,错误代码返回顶部 2,至少一个参数没有被指定值. 1.B,出错原因分析返回顶部 未解决 1.C, ...
- 企业高并发的成熟解决方案(一)video(笔记&知识点)
知识点 答案 什么是高可用(HA) 高并发发生在哪两处 app服务器会出现什么问题,有哪些解决方案? 数据库并发有什么要求? hadoop集群的作用 负载均衡的功能有哪些 负载均衡的分类 哪种负载均衡 ...
- python在linux上的GUI无法弹出界面
在进行python写GUI程序的时候,使用Tkinter,发现无法执行程序,报错如下: X connection to localhost:10.0 broken(explicit kill or s ...