【优先队列】结构体优先队列自定义排序
2021-03-14 00:47:00 # ACM

重定义的时候就如写$sort$时的$cmp$一样,最后将$return$时候的$”>”,”<”$反过来就行

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
//#pragma GCC optimize("O2")
using namespace std;
#define LL long long
#define ll long long
#define ULL unsigned long long
#define ls rt<<1
#define rs rt<<1|1
#define one first
#define two second
#define MS 500009
#define INF 1e18
#define mod 998244353
#define Pi acos(-1.0)
#define Pair pair<LL,LL>
#define eps 1e-9

LL n,m,k;
struct node{
LL a,b,pos;
}p[MS];

bool operator < (node x,node y){
if(x.b == y.b) return x.a < y.a; // b相等时 ,a从 大到小 排序
return x.b > y.b; // b 从 小到大 排序
}

priority_queue<node > Q;

int main(){
ios::sync_with_stdio(false);
cin >> n;
for(int i=1;i<=n;i++){
LL t1,t2;
cin >> t1 >> t2;
p[i] = {t1,t2,i};
Q.push(p[i]);
}
while(!Q.empty()){
node e = Q.top();
cout << e.a << " " << e.b << " " << e.pos << endl;
Q.pop();
}


return 0;
}

/*
5
5 5
5 4
4 2
4 1
2 1

4 1 4
2 1 5
4 2 3
5 4 2
5 5 1
*/


Prev
2021-03-14 00:47:00 # ACM
Next