Alisha’s Party
要注意一点输入人名后的输入后要进行排序处理(从小到大)
照着网上的代码,敲了一遍自己的:
#include<bits/stdc++.h>
using namespace std;
struct node{
int time;
int v;
friend bool operator <(node n1,node n2)
{
if(n1.v==n2.v)
return n1.time>n2.time;
return n1.v<n2.v;
}
}a[150005],h;
struct ss{
int diji;
int jige;
}b[150005];
bool cmp(ss d,ss c)
{
return d.diji<c.diji;
}
char name[150005][205];
int num[150005];
int main()
{
int t;
int qury;
scanf("%d",&t);
while(t--)
{
priority_queue<node>q;
int k,m,qqq;
scanf("%d%d%d",&k,&m,&qqq);
for(int i=1;i<=k;i++)
{
scanf("%s%d",name[i],&a[i].v);
a[i].time=i;
}
for(int i=1;i<=m;i++)
{
scanf("%d%d",&b[i].diji,&b[i].jige);
}
sort(b+1,b+m+1,cmp);
int j=1;
int ans=1;
for(int i=1;i<=m;i++)
{
while(j<=b[i].diji&&j<=k)
{
q.push(a[j]);
j++;
}
int w=0;
while(w<b[i].jige&&!q.empty())
{
h=q.top();
num[ans++]=h.time;
q.pop();
w++;
}
}//后面的是处理最后一起进去的
for(int i=j;i<=k;i++)
{
q.push(a[i]);
}
while(!q.empty())
{
h=q.top();
num[ans++]=h.time;
q.pop();
}
for(int i=0;i<qqq;i++)
{
scanf("%d",&qury);
if(i==qqq-1)
{
printf("%s\n",name[num[qury]]);
}
else
printf("%s ",name[num[qury]]);
}
}
return 0;
}