结构体优先队列自定义排序

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

#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
*/ 

 
posted @ 2021-03-14 00:47  棉被sunlie  阅读(107)  评论(0)    收藏  举报