优先队列
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