Director_Ni @ 2023-10-17 21:53:28
为啥没说明数据规模 下面附80分代码
#include <bits/stdc++.h>
using namespace std;
struct EDGE {int n,y,z;}e[1090009];
bool cmp(EDGE p,EDGE q){
return p.z>q.z;
}
int main()
{
int np,a,b,c;
scanf("%d",&np);
for(int i=1;i<=np;++i){
scanf("%d%d%d",&a,&b,&c);
e[i].n=i;e[i].y=a;e[i].z=(a+b+c);
}
sort(e+1,e+1+np,cmp);
int cnt=0;
for(int i=1;i<=5;i++){
if(e[i].z!=e[i+1].z){
cout<<e[i].n<<" "<<e[i].z<<endl;
}
else if(e[i].y!=e[i+1].y){
if(e[i].y<e[i+1].y){
swap (e[i],e[i+1]);
}
cout<<e[i].n<<" "<<e[i].z<<endl;
}
else{
if(e[i].n>e[i+1].n){
swap (e[i],e[i+1]);
}
cout<<e[i].n<<" "<<e[i].z<<endl;
}
}
return 0;
}
求大佬帮调
by littlesnake @ 2023-10-18 17:07:26
#include <bits/stdc++.h>
using namespace std;
const int N=310;
struct node{
//num:学号
//因为排序会改变顺序
//所以学号要提前记下来
//sum:总分
int num,x,y,z,sum;
}a[N];
int n;
//按题目所给的规则排序
bool cmp(node n1,node n2){
if(n1.sum!=n2.sum){
return n1.sum>n2.sum;
}else{
if(n1.x!=n2.x){
return n1.x>n2.x;
}else{
return n1.num<n2.num;
}
}
}
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d %d %d",&a[i].x,&a[i].y,&a[i].z);
a[i].num=i;
a[i].sum=a[i].x+a[i].y+a[i].z;
}
sort(a+1,a+n+1,cmp);
for(int i=1;i<=5;i++){
printf("%d %d\n",a[i].num,a[i].sum);
}
return 0;
}
by littlesnake @ 2023-10-18 17:08:53
你直接把排序规则在cmp函数里写完就行了,不用那么复杂,找bug很难要是写那么长的话