摘要: 优先队列用法在优先队列中,优先级高的元素先出队列。标准库默认使用元素类型的<操作符来确定它们之间的优先级关系。优先队列的第一种用法,也是最常用的用法:priority_queue<int>qi;通过<操作符可知在整数中元素大的优先级高。故示例1中输出结果为:96532第二种方法:在示例1中,如果我们要把元素从小到大输出怎么办呢?这时我们可以传入一个比较函数,使用functional.h函数对象作为比较函数。priority_queue<int,vector<int>,greater<int>>qi2;其中第二个参数为容器类型。第二个参 阅读全文
posted @ 2012-12-01 23:27 紫忆 阅读(714) 评论(0) 推荐(0) 编辑
摘要: #include<iostream>#include<queue>using namespace std;struct ss{ friend bool operator<(const ss a,const ss b) { if(a.v<b.v) return 1; else if(a.v==b.v&&a.num>b.num) return 1; else return 0; } int num,v;};int main(){ int n; while(scanf("%d",&n)>0) { ss t; 阅读全文
posted @ 2012-12-01 23:25 紫忆 阅读(256) 评论(0) 推荐(0) 编辑