题意:给你id,还有它出现的频率,问前k次出现的id
思路:id出现一次之后再加上本身的频率,然后重新插入到队列中,题目要找出现有队列中的最小值,用优先队列
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<queue>
using namespace std;
struct node{
int id,value;
friend bool operator<(node a,node b)
{
if(a.value!=b.value)return a.value>b.value;
return a.id>b.id;
}
};
int main()
{
int n,key[10000],i,m;
char str[20];
node p;
priority_queue<node>q;
while(scanf("%s",str)&&str[0]!='#')
{
scanf("%d%d",&i,&m);
key[i]=m;
p.id=i,p.value=m;
q.push(p);
}
scanf("%d",&n);
while(n--)
{
p=q.top();
q.pop();
printf("%d\n",p.id);
p.value+=key[p.id];
q.push(p);
}
}