C++优先队列的用法
#include<iostream>#include<queue>#include<cstring>using namespace std;int a[1000010];bool cmp(int a,int b){return a>b;}struct node{int a,b;node (int a,int b){thi...
·
#include<iostream>
#include<queue>
#include<cstring>
using namespace std;
int a[1000010];
bool cmp(int a,int b){
return a>b;
}
struct node{
int a,b;
node (int a,int b)
{
this->a=a;
this->b=b;
}
bool operator <(const node &w)const
{
if(a!=w.a)
return a>w.a;
else
return b>w.b;
}
};
int main(){
int n,m;
int i=0;
priority_queue<node>Q;
while(scanf("%d%d",&n,&m)&&(n||m)){
Q.push(node(n,m));
}
while(!Q.empty())
{
cout<<Q.top().a<<' '<<Q.top().b<<endl;
Q.pop();
}
return 0;
}
更多推荐
已为社区贡献2条内容
所有评论(0)