priority_queue自定义排序
作者:
walmpooer
,
2024-03-23 15:13:36
,
所有人可见
,
阅读 7
# include<iostream>
# include<cstring>
# include<queue>
# include<vector>
# include<algorithm>
using namespace std;
#define x first
#define y second
typedef pair<int,int> PII;
struct cmp{
bool operator()(PII a, PII b)
{
if(a.x!=b.x) return a.x>b.x;
else return a.y>b.y;
}
};
PII p[5] = {{3,3},{3,1},{5,1},{5,0},{1,10}};
int main()
{
priority_queue<PII,vector<PII>,cmp> q;
for(int i = 0; i<5; i++) q.push(p[i]);
for(int i = 0; i<5; i++)
{
PII tmp = q.top();
q.pop();
cout<<tmp.x<<" "<<tmp.y<<endl;
}
}