题解 P1093 [NOIP 2007 普及组] 奖学金
快速的堆排模版
这道题只需要将结构体重载小于运算符再用优先队列就可以过了。
#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;
}