hdu 5437
Alisha’s Party
Time Limit: 3000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 7514    Accepted Submission(s): 1748
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. Biis 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.
5 2 3
Sorey 3
Rose 3
Maltran 3
Lailah 5
Mikleo 6
1 1
4 2
1 2 3
#include <iostream>
#include <vector>
#include <cstdio>
#include <queue>
#include <cstring>
#include <cstdlib>
#include <algorithm>
using namespace std;
#define P pair<int,int>
#define ph push_back
#define ll long long
#define N 150009
#define fi first
#define se second
int t,n,m,q;
struct Ma{
string s;
int val,id;
bool operator <(const Ma&a)const{
if(val!=a.val)
return val<a.val;
return id>a.id;
}
}ma[N];
struct Node{
int time,p;
}nod[N];
bool cmp(Node a,Node b)
{
return a.time<b.time;
}
string ret[N];
char ss[];
int main()
{
scanf("%d",&t);
while(t--)
{
scanf("%d%d%d",&n,&m,&q);
for(int i=;i<=n;i++)
{
scanf("%s%d",ss,&ma[i].val);
ma[i].s=ss;
ma[i].id=i;
}
for(int i=;i<m;i++)
{
scanf("%d%d",&nod[i].time,&nod[i].p);
}
sort(nod,nod+m,cmp);
priority_queue<Ma>que;
int pos=,cnt=;
for(int i=;i<m;i++)
{
while(pos<=nod[i].time){
que.push(ma[pos]);//pos容易写错
pos++;
}
for(int j=;j<nod[i].p;j++)
{
if(que.empty()) break;//小于p个人,都进去
Ma x=que.top();que.pop();
ret[cnt++]=x.s;
}
}
while(pos<=n)
{
que.push(ma[pos]);
pos++;
}
while(!que.empty()){
Ma x=que.top();que.pop();
ret[cnt++]=x.s;
}
int y;
for(int l=;l<q;l++)
{
scanf("%d",&y);
printf("%s%c",ret[y].c_str(),l==q-?'\n':' ');
}
}
return ;
}
hdu 5437的更多相关文章
- 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 优先队列+模拟 **
		比赛的时候虽然考虑到没门的情况,但是写了几组都能过,就没想了,23333,差一行代码就能A,遗憾~~ #include<cstdio> #include<iostream> # ... 
- 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 (优先队列模拟)
		题意:邀请k个朋友,每个朋友带有礼物价值不一,m次开门,每次开门让一定人数p(如果门外人数少于p,全都进去)进来,当最后所有人都到了还会再开一次门,让还没进来的人进来,每次都是礼物价值高的人先进.最后 ... 
- 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
		题意:有k个人带着价值vi的礼物来,开m次门,每次在有t个人来的时候开门放进来p个人,所有人都来了之后再开一次门把剩下的人都放进来,每次带礼物价值高的人先进,价值相同先来先进,q次询问,询问第n个进来 ... 
- hdu 5437(优先队列模拟)
		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) ... 
随机推荐
- session是什么时候创建的
			总结:session不是一打开网站就会立刻建立.它的建立需要基于下面两个条件中的任意一个: 1:在servlet中手动调用 HttpSession session = request.getSessi ... 
- 详细说明phpmyadmin连接,管理多个mysql服务器
			用phpmyadimn来连接管理多个数据库要修改配置文件,挺不爽的,并且连接远程数据库,速度不行.可以使用其他数据库管理工具,请参考,navicat 结合快捷键 非常好用,开源,好用mysql 管理工 ... 
- arcengine geometry  union操作
			以前得到的结果老是某一个,用下面的方法就可以获取合并后的结果 IGeometry pUnionGeo = null; var bFirst = true; foreach (IGeometry pGe ... 
- STL使用迭代器逆向删除
			网上有很多这种例子: void erase(vector<int> &v) { for(vector<int>::reverse_iterator ri=v.rbegi ... 
- 在PaaS上开发Web、移动应用(2)
			在PaaS上开发Web.移动应用(2) PaaS学习笔记目录 PaaS基础学习(1) 在PaaS上开发Web.移动应用(2) PaaS优点与限制(3) 6. 巨型代码,是指持续不断地向一个应用程序添加 ... 
- webview.loadUrl()可能会URLDecoder
			与服务器交互时,客户端对userId进行了URLEncoder,然后在webview.loadUrl时将userId传给服务端,服务端再 URLDecoder userId 可是神奇的事情出现了,客户 ... 
- Git服务器和Git权限管理应用GITLAB安装方法
			首先声明,本文使用的服务器是Centos 6.5,在其他版本的LINUX上运行不保证也是一样的效果. 顺便说下 来波点赞 来波收藏和推荐 有什么问题 我会一直关注评论的 想放一张最终图吧 其中主要涉 ... 
- int型除以int型
			int型除以int型得到的还是int型 就算你是这样的:float a = 5/3,虽然你定义的a是float型,但a得到的结果依旧是1.0000而不是1.66666 5/3先得到1,然后再转换成1. ... 
- pandas小结
			pandas part I: # 总结: DataFrame.loc[0:5] 一共6行数据,而切片[0:5]只有5个数据 在对df的行数据删除后,有些index已缺失,此时用 iloc[]来按照位置 ... 
- Linux之centos7 VMware安装教程
			Linux系统安装 下面是centOS7的安装过程 VMware 系统搭建 1 新建虚拟机 2 选择自定义 3 选择稍后安装操作系统 4 选择操作系统的版本Linux centos64位 5 选择处理 ... 
