Alisha’s Party
Alisha’s Party
Time Limit: 3000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 1815 Accepted Submission(s): 487
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.
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.
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<stack>
#include<vector>
#include<algorithm> using namespace std; #define maxn 150008
char name[maxn][]; struct node
{
int v, id;
bool operator < (const node &t)const
{
if(v == t.v)
return id > t.id;
return v < t.v;
}
}p[maxn]; struct people
{
int t, p;
bool operator < (const people &k)const
{
return t < k.t;
}
}a[maxn]; int cnt[maxn]; int main()
{
int c, k, m, q, s, g, z;
scanf("%d", &c); while(c--)
{
g = ;
s = ;
priority_queue<node> Q;
scanf("%d%d%d", &k, &m, &q);
for(int i = ; i < k; i++) // 关系全让 下标 i 联系~
{
scanf("%s", name[i]);
scanf("%d", &p[i].v);
p[i].id = i;
}
for(int i = ; i < m; i++)
scanf("%d %d", &a[i].t, &a[i].p);
sort(a, a+m); // 坑点,输入的当第几个人到的开门不按顺序,要排序^^……^
for(int i = ; i < m; i++)
{
for(; s < a[i].t; s++)
Q.push(p[s]);
while(Q.size() && a[i].p)
{
node u = Q.top();
Q.pop();
cnt[g++] = u.id;
a[i].p--;
}
}
for(; s < k; s++)
Q.push(p[s]); // m次开门后如果还有人没进,一次依次进去
while(Q.size())
{
node u = Q.top();
Q.pop();
cnt[g++] = u.id;
}
while(q--)
{
scanf("%d", &z); if(q >= )
printf("%s ", name[cnt[z]]);
else
printf("%s\n", name[cnt[z]]);
}
}
return ;
}
Alisha’s Party的更多相关文章
- 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 (优先队列)——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 优先队列
Alisha’s Party Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/contests/contest_sh ...
- HDU5437 Alisha’s Party (优先队列 + 模拟)
Alisha’s Party Time Limit: 3000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) ...
- Alisha’s Party(队列)
Alisha’s Party Time Limit: 3000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) ...
- Alisha’s Party (HDU5437)优先队列+模拟
Alisha 举办聚会,会在一定朋友到达时打开门,并允许相应数量的朋友进入,带的礼物价值大的先进,最后一个人到达之后放外面的所有人进来.用优先队列模拟即可.需要定义朋友结构体,存储每个人的到达顺序以及 ...
- Alisha's Party
Alisha’s Party Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid ...
- 优先队列 + 模拟 - 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) ...
随机推荐
- 35 怎么优化join
35 怎么优化join 上一篇介绍了join的两种算法:nlj和bnl create table t1(id int primary key, a int, b int, index(a)); cre ...
- JS 数组的常用方法归纳之不改变原数组和其他
不改变原数组的方法 concat() 连接两个或多个数组,不改变现有数组,返回新数组,添加的是数组中的元素 join(",") 把数组中的所有元素放入一个字符串,通过‘,’分隔符进 ...
- java webservice - cxf使用总结 一
1.创建maven项目 加入pom依赖 <dependency> <groupId>org.apache.cxf</groupId> <artifactId& ...
- BAT程序员常用的开发工具,建议收藏!
今天给大家推荐一批 BAT 公司常用的开发工具,个个好用,建议转发+收藏. 阿里篇 一.Java 线上诊断工具 Arthas Arthas 是阿里巴巴 2018 年 9 月开源的一款 Java 线上诊 ...
- docker pull使用 代理
[root@fdfs- ~]# cat /usr/lib/systemd/system/docker.service [Unit] Description=Docker Application Con ...
- pip源地址
pip国内的一些镜像 阿里云 http://mirrors.aliyun.com/pypi/simple/ 中国科技大学 https://pypi.mirrors.ustc.edu.cn/si ...
- <meta>标签中http-equiv属性的属性值X-UA-Compatible详解
X-UA-Compatible是针对IE8新加的一个设置,对于IE8之外的浏览器是不识别的,这个区别与content="IE=7"在无论页面是否包含<!DOCTYPE> ...
- Java7/8 中的 HashMap 和 ConcurrentHashMap 全解析 (转)
阅读前提:本文分析的是源码,所以至少读者要熟悉它们的接口使用,同时,对于并发,读者至少要知道 CAS.ReentrantLock.UNSAFE 操作这几个基本的知识,文中不会对这些知识进行介绍.Jav ...
- JSP学习(5)
JSP学习(5) 保存用户状态的两大机制 session对象 Cookie Cookie简介 是Web服务器保存在客户端的一系列文本信息 典型应用 判断注册用户是否已经登录 购物车处理 作用 对特定对 ...
- Sql Server 出现此数据库没有有效所有者问题
在新建数据库或附加数据库后,想添加关系表,结果出现下面的错误: 此数据库没有有效所有者,因此无法安装数据库关系图支持对象.若要继续,请首先使用“数据库属性”对话框的“文件”页或ALTER AUTHO ...