優先隊列多級排序

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>
#define LL long long
using namespace std;

struct node
{
    int num,data;
    friend bool operator<(node a,node b)
    {
        if(a.data==b.data)
        {
            return a.num>b.num;
        }
        else
        {
            return a.data<b.data;
        }
    }
}a;
int main()
{
    int i;
   priority_queue<node>Q;
   int n;
   cin>>n;
   for(i=0;i<n;i++)
   {
       scanf("%d",&a.data);
       a.num=i;
       Q.push(a);
   }
   while(!Q.empty())
   {
       a=Q.top();
       Q.pop();
       printf("%d %d\n",a.num,a.data);
   }
   return 0;
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章