平时定义的时候,直接上就完事了:

priority_queue<int>Q;

默认大根堆。

之前很菜的时候不知道小根堆怎么写,还在考场上干过加个负号甩到大根堆里面去的蠢事。

它的完整形式呢,其实是长这个样子的:

 

//小根堆
priority_queue <int,vector<int>,greater<int> > Q;
//大根堆
priority_queue <int,vector<int>,less<int> >Q;

 

 

然后就是一些特殊的情况:

用pair的时候,先按first,再按second 自动排序 。

priority_queue<pair<int,int> >Q;

 

如果要自定义排序的话,可以写一个$cmp$:

struct node{
    int a,b;
}num[N];
struct cmp
{
    bool operator()(const int &p,const int &q)
    {
        if(num[p].b<num[q].b) return 1;
        else return 0;
    }
};
priority_queue<int,vector<int>,cmp> Q;

 

To be continue...

 

相关文章:

  • 2021-07-18
  • 2022-12-23
  • 2022-12-23
  • 2021-05-26
  • 2021-07-23
  • 2021-08-09
  • 2022-01-07
  • 2021-08-19
猜你喜欢
  • 2021-11-22
  • 2021-12-10
  • 2021-11-20
  • 2021-12-13
  • 2022-01-30
  • 2022-01-12
  • 2021-11-07
相关资源
相似解决方案