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

 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 }

 

相关文章:

  • 2022-12-23
  • 2021-08-13
  • 2022-02-14
  • 2021-07-12
  • 2021-06-03
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-10-23
  • 2022-01-27
  • 2021-05-07
  • 2021-12-24
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案