优先队列模版

#include<iostream>
#include<queue>
#include <vector>
#include<stdio.h>
using namespace std;
struct cp1
{
    bool operator()(int x,int y)
    {
    return x<y;
    }
};
struct cp2
{
    int x,y;
    friend bool operator<(cp2 a,cp2 b)
    {
        if(a.x==b.x)
        return a.y>b.y;
        return a.x>b.x;

    }
};
priority_queue<int ,vector<int>,cp1> q1;
priority_queue<cp2> q2;
int main()
{
    cp2 a;
    while(scanf("%d %d",&a.x,&a.y)&&(a.x+a.y))
    {
        q2.push(a);
    }
    while(!q2.empty())
    {
        cout<<q2.top().x<<q2.top().y<<endl;
        q2.pop();
    }
    return 0;
}

你可能感兴趣的:(优先队列模版)