跳到正文

题解

题解 P1093 [NOIP 2007 普及组] 奖学金

xiyangz约 1 分钟
原文
文章信息与版本

文章信息

发布
2025年4月3日
收录
2025年12月12日
更新
2026年11月20日
篇幅
约 1 分钟

版本

  1. v1当前

快速的堆排模版

这道题只需要将结构体重载小于运算符再用优先队列就可以过了。

C++
#include<iostream>
#include<queue>
using namespace std;
struct node{
	int id,yu,shu,ying,zhong;
    bool operator<(node x)const
    {
        if(x.zhong!=zhong)return x.zhong>zhong;
        if(x.yu!=yu)return x.yu>yu;
        return x.id<id; 
    }
};
priority_queue<node>pq;
int n;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        int x,y,z;
        cin>>x>>y>>z;
        pq.push(node{i,x,y,z,x+y+z});
    }
    int tot=0;
    while(!pq.empty())
    {
        tot++;
        if(tot<=5)cout<<pq.top().id<<" "<<pq.top().zhong<<endl;
        else break;
        pq.pop();
    }
    return 0;
}
原文