结构体优先队列排序

结构体某一个元素越小,优先级越大。

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<algorithm>
 4 #include<queue>
 5 using namespace std;
 6 int ans[300010];
 7 struct node{
 8     int a,w;
 9 }s[100];
10 bool operator<( node a, node b ){
11     if(a.a == b.a) return a.w>b.w;
12     return a.a>b.a;
13 }
14 main()
15 {
16     int i;
17     priority_queue<node>Q;
18     node e;
19     for(i=1;i<=10;i++)
20     {
21         scanf("%d%d",&s[i].a,&s[i].w);
22         Q.push(s[i]);
23     }
24     for(i=1;i<=10;i++)
25     {
26         e=Q.top();
27         printf("%d %d
",e.a,e.w);
28         Q.pop();
29     }
30 }
原文地址:https://www.cnblogs.com/CrazyBaby/p/5750283.html