优先队列+pair
时间:2020-05-24 01:05:36
收藏:0
阅读:378
一、根据pair的first降序排序,second升序排序

//#include<utility> typedef pair<int,int> P; struct cmp { bool operator()(const P p1,const P p2) { if(p1.first==p2.first) return p1.second>p2.second; else return p1.first<p2.first; } }; priority_queue < P, vector<P>, cmp > que;
priority_queue < int, vector<int>, greater<int> > que;默认升序
priority_queue < int > que;默认降序
二、根据struct的x降序排序,y升序排序

1 struct p{ 2 int x,y; 3 }aa[10]; 4 bool cmp(p a,p b) 5 { 6 if(a.x==b.x) return a.y<=b.y; 7 return a.x>b.x; 8 } 9 sort(aa,aa+n,cmp);
原文:https://www.cnblogs.com/xxxinnn/p/12945332.html
评论(0)