优先队列学习

优先队列

priority_queue
即在队列中排队
1.头文件
#include< queue>;
using namespace std;
2.基本格式
priority_queue<结构类型>队列名;
3.priority_queue< int>i;
.默认的排列为从大到小排列
4.结构体自定义排序方法
在这里表示一下简单写法

在这里struct node
{
    int d,w;
};
bool operator<(const node &x,const node &y)
{
    if(y.w==x.w)
        return x.d>y.d;
    else
        return x.w>y.w;
}
int main()
{
    priority_queue<node>q;//node为结构体
}
//另一种写法
struct node
{
    int x,y;
    bool operator <(const node &a)const 
    {
        return x<a.x;//这个意思为按x的序列排队 <为降序 >为升序
    }
};


5.less greater

priority_queue<int,vector<int>,less<int> >q;//从大到小排列
priority_queue<int,vector<int>,greater<int> >q;//从小到大排列

6.应用(复制粘贴的hhhh)
http://acm.hdu.edu.cn/showproblem.php?pid=1242
http://acm.hdu.edu.cn/showproblem.php?pid=1053
http://acm.pku.edu.cn/JudgeOnline/problem?id=2263

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值