优先队列
1 priority_queue<int, vector<int>, cmp > q2;
2 struct cmp{
3 bool operator () (const int &a, const int &b){
4 return a>b;
5 }
6 };
7
8
9
10 #include <queue>
11 using namespace std;
12
13 struct cmp{
14 bool operator ()(int a,int b){ //通过传入不同类型来定义不同类型优先级
15 return a>b; //最小值优先
16 }
17 };
18 /**
19 struct cmp{
20 bool operator ()(int a,int b){
21 return a<b; //最大值优先
22 }
23 };
24 **/
25
26
27 priority_queue<int, vector<int>, cmp > q
28
29 #include <iostream>
30 #include <queue>
31 #include <vector>
32 #include <cstdio>
33 #include <cstring>
34
35 using namespace std;
36 struct cmp1
37 {
38 bool operator()(int x, int y)
39 {
40 return x > y;//小的优先级高
41 }
42 };
43
44 struct node
45 {
46 int x;
47 int y;
48 friend bool operator <(const node &a, const node &b)
49 {
50 return a.x > b.x;//小的优先级高
51 }
52 };
53 priority_queue<int, vector<int>,cmp1>q2;
54 priority_queue<node>q3;
55 int main()
56 {
57 int n;
58 scanf("%d", &n);
59 for(int i = 0; i < n; i ++)
60 {
61 node a;
62 cin>>a.x>>a.y;
63 q3.push(a);
64 }
65 cout<<endl;
66 while(!q3.empty())
67 {
68 cout<<q3.top().x<<" "<<q3.top().y<<endl;
69 q3.pop();
70 }
71
72 return 0;
73 }
转载于//www.cnblogs.com/coodyz/p/10596865.html
还没有评论,来说两句吧...