优先队列
2016-01-26 21:49
190 查看
为了明天的讲课 今天一直在看广搜 队列 优先队列 算是自己又多了点知识 学长说看我紧张成这样 好吧他明天讲吧 啊 心一下放松了
今天死磕优先队列了 好吧 来写一下总结
优先队列 我认为就是从一堆数据中挑优先级别高的出队 并不是像对列一样先进先出
优先级的大小是自己定义的 operator是一个重载
比如我现在想让x小的先出队 我就可以这样写
struct node
{
int x,y;
bool operator(const node &n1)const
{
return x>n1.x;
}
}
或者
struct node
{
int x,y;
friend bool operatop(const node n1,const node n2)
{
returen n1.x>n2.x;
}
}
运用优先队列 就是 priority_queue<node>Q;
优先队列 就像一个cmp差不多 可以直接用sort 排序结构体
比如:
可能还有好多我不知道的功能 今天就先说到这里 我们下周同一时间再见(哈哈)
以后慢慢发现慢慢更新
今天死磕优先队列了 好吧 来写一下总结
优先队列 我认为就是从一堆数据中挑优先级别高的出队 并不是像对列一样先进先出
优先级的大小是自己定义的 operator是一个重载
比如我现在想让x小的先出队 我就可以这样写
struct node
{
int x,y;
bool operator(const node &n1)const
{
return x>n1.x;
}
}
或者
struct node
{
int x,y;
friend bool operatop(const node n1,const node n2)
{
returen n1.x>n2.x;
}
}
运用优先队列 就是 priority_queue<node>Q;
优先队列 就像一个cmp差不多 可以直接用sort 排序结构体
比如:
#include<stdio.h> #include<string.h> #include<stdlib.h> #include<iostream> #include<algorithm> #include<math.h> #include<queue> #define N 220 using namespace std; struct node { int x,y; bool operator<(node n1)const { return x>n1.x; } }; int main() { node a ; int n; scanf("%d",&n); for(int i=0;i<n;i++) { scanf("%d %d",&a[i].x,&a[i].y); } sort(a,a+n); for(int i=0;i<n;i++) { printf("%d %d\n",a[i].x,a[i].y); } return 0; }
可能还有好多我不知道的功能 今天就先说到这里 我们下周同一时间再见(哈哈)
以后慢慢发现慢慢更新
相关文章推荐
- 将Maven的Java Project转换或修改为Web Project
- 关于Redis持久化
- poj-2481-Cows
- socket通信简介
- USACO--Transformations
- Parcel相关
- 51NOD 1133 不重叠的线段
- spring mvc 拦截器
- 源码编译php5.4 ./configure参数
- angularjs 合并单元格
- Jackson 框架,轻易转换JSON
- 文本项目系列[1]——逆序字符串
- OpenGL实现多层绘制(Layered Rendering)
- Tiger小屋:微信的多客服功能,在自定义菜单中的实现
- Spring Data学习笔记
- 微信企业号开发(4)--管理通讯录(部门)
- 好玩的智力小游戏(海盗分金)
- 泛型的使用
- 不在JPA 的 persistence.xml 文件中配置Entity class的解决办法
- Delphi 7中ADO控件打开Access数据库文件