结构体优先队列排序

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

 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\n",e.a,e.w);
28         Q.pop();
29     }
30 }

 

posted @ 2016-08-08 17:24  Crazy、baby  阅读(982)  评论(0编辑  收藏  举报