标签:
题目链接:
http://acm.split.hdu.edu.cn/showproblem.php?pid=5437
Hint:
题意:
给出k,m,q。k表示参加聚会的人数,m表示会开门的次数,q表示询问的次数。
m中有t,p。表示当到达会场的人数达到t的时候,就有p个人可以进入。
题解:
优先队列加模拟。
代码:
#include <cmath>
#include <cstdio>
#include <queue>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 150000+10;
#define met(a,b) memset(a,b,sizeof(a))
char ans[maxn][200+10];
struct node
{
char name[200+10];
int time;
int val;
friend bool operator < (node a,node b)
{
if(a.val==b.val)
return a.time>b.time;
return a.val<b.val;
}
}s[maxn];
struct node1
{
int t,p;
}d[maxn];
int cmp(node1 a,node1 b)
{
return a.t<b.t;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int k,m,q;
scanf("%d%d%d",&k,&m,&q);
for(int i=1;i<=k;i++)
{
scanf("%s %d",s[i].name,&s[i].val);
s[i].time=i;
}
for(int i=1;i<=m;i++)
scanf("%d%d",&d[i].t,&d[i].p);
sort(d+1,d+1+m,cmp);
priority_queue<node>que;
while(!que.empty())
que.pop();
int j=1,l=1;
for(int i=1;i<=m;i++)
{
while(j<=k&&j<=d[i].t)
{
que.push(s[j]);
j++;
}
int num=d[i].p;
while(!que.empty()&&num--)
{
node a=que.top();
que.pop();
strcpy(ans[l++],a.name);
}
}
while(j<=k)
{
que.push(s[j]);
j++;
}
while(!que.empty())
{
node a=que.top();
que.pop();
strcpy(ans[l++],a.name);
}
for(int i=1;i<=q;i++)
{
int x;
scanf("%d",&x);
if(i!=q)
printf("%s ",ans[x]);
else
printf("%s\n",ans[x]);
}
}
}
标签:
原文地址:http://www.cnblogs.com/TAT1122/p/5835418.html