1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <string> 5 #include <utility> 6 #include <algorithm> 7 #include <vector> 8 #include <queue> 9 #include <stack> 10 #include <cmath> 11 #include <set> 12 #include <map> 13 using namespace std; 14 #define max(x,y) x>=y?x:y 15 #define lowbit(x) x&(-x) 16 typedef long long ll; 17 using namespace std; 18 int main() 19 { 20 priority_queue<int>q1; 21 priority_queue<int,vector<int>,greater<int> >q2;//top最小 22 for (int i=1;i<=5;i++) 23 { 24 q1.push(i); 25 q2.push(i); 26 } 27 while(!q1.empty()) 28 { 29 cout<<q1.top()<<endl; 30 q1.pop(); 31 } 32 cout<<"\n\n\n"; 33 while(!q2.empty()) 34 { 35 cout<<q2.top()<<endl; 36 q2.pop(); 37 } 38 return 0; 39 40 /* 41 5 42 4 43 3 44 2 45 1 46 47 48 49 1 50 2 51 3 52 4 53 5 54 */ 55 56 57 #include <iostream> 58 #include <cstdio> 59 #include <cstring> 60 #include <queue> 61 using namespace std; 62 /* 63 struct Node{ 64 int w,id; 65 Node(){} 66 Node(int w,int id):w(w),id(id){} 67 bool operator <(const Node &a)const{ 68 if(w==a.w) 69 return id<a.id; 70 return w<a.w; 71 } 72 73 1 2 2 3 3 74 75 76 3 5 77 3 4 78 2 3 79 2 2 80 1 1 81 }; 82 */ 83 struct Node{ 84 int w,id; 85 Node(){} 86 Node(int w,int id):w(w),id(id){} 87 bool operator <(const Node &a)const{ 88 if(w==a.w) 89 return id>a.id; 90 return w>a.w; 91 } 92 /* 93 1 2 2 3 3 94 95 96 1 1 97 2 2 98 2 3 99 3 4 100 3 5 101 */ 102 103 }; 104 int main() 105 { 106 priority_queue<Node>q; 107 int x; 108 for(int i=1;i<=5;i++) 109 { 110 scanf("%d",&x); 111 q.push(Node(x,i)); 112 } 113 114 while(!q.empty()){ 115 Node tmp=q.top(); 116 q.pop(); 117 printf("%d %d\n",tmp.w,tmp.id); 118 } 119 return 0; 120 }
priority_queue<P,vector<P>,greater<P> >Q;
for(int i=0;i<n;i++){
scanf("%lld%lld",&x,&y);
Q.push(P(x,y));
}
while(!Q.empty()){
P p = Q.top();
ll x= p.first;
ll y = p.second;
Q.pop();
printf("%lld %lld \n",x,y);
}
1 5
2 4
1 6
1 5
1 6
2 4ios
#include <iostream> #include <cstdio> #include <cstring> #include <queue> #include <algorithm> using namespace std; const int N=10; int a[N]; bool cmp(int x,int y){ return x<y; } int main() { for(int i =1;i<=5;i++) a[i-1]=i; sort(a,a+5,cmp); for(int i =0;i<5;i++) { printf("%d\n",a[i]); } 1 2 3 4 5 return 0; }