看不出来有错 ,但#5 #10过不了,求调

P1093 [NOIP2007 普及组] 奖学金

shuiren @ 2023-08-07 21:15:00

#include<bits/stdc++.h>
using namespace std;
int n;
int x,y,z; 
struct st{
    int sum,yy,num;
}a[305];
bool cmp(st q,st w){
    return q.sum>w.sum||
    q.sum==w.sum&&q.yy>w.yy||
    q.yy==w.yy&&q.num<w.num;
}
int main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>x>>y>>z;
        a[i].sum=x+y+z;
        a[i].yy=x;
        a[i].num=i;
    }
    sort(a+1,a+n+1,cmp);
    for(int i=1;i<=5;i++){
        cout<<a[i].num<<' '<<a[i].sum;
        cout<<endl; 
    }
    return 0;
}

by shuiren @ 2023-08-07 21:16:04

去年打的代码今年还是对不了……


by luogu官方测试员 @ 2023-08-09 19:31:28

ac code

求关注,谢谢

//他人代码,帮调 

#include<bits/stdc++.h>
using namespace std;
int n;
int x,y,z; 
struct st{
    int sum,yy,num;
}a[305];
bool cmp(st q,st w){
    return q.sum>w.sum||
    (q.sum==w.sum&&q.yy>w.yy)||
    (q.yy==w.yy&&q.num<w.num&&q.sum==w.sum);

    //错误情况 :q.s < w.s && q.y == w.y && q.num < w.num
    //当q.s < w.s : q.sum > w.sum 和q.s == w.sum && q.yy > w.yy都成假,可如果q.yy == w.yy且q.num < w.num,顺序则会出问题,so,再加一条q.sum == w.sum 即可 
}
int main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>x>>y>>z;
        a[i].sum=x+y+z;
        a[i].yy=x;
        a[i].num=i;
    }
    sort(a+1,a+n+1,cmp);
    for(int i=1;i<=5;i++){
        cout<<a[i].num<<' '<<a[i].sum;
        cout<<endl; 
    }
    return 0;
}

by luogu官方测试员 @ 2023-08-10 10:21:50

@shuiren

ac code

求关注,谢谢

//他人代码,帮调 

#include<bits/stdc++.h>
using namespace std;
int n;
int x,y,z; 
struct st{
    int sum,yy,num;
}a[305];
bool cmp(st q,st w){
    return q.sum>w.sum||
    (q.sum==w.sum&&q.yy>w.yy)||
    (q.yy==w.yy&&q.num<w.num&&q.sum==w.sum);

    //错误情况 :q.s < w.s && q.y == w.y && q.num < w.num
    //当q.s < w.s : q.sum > w.sum 和q.s == w.sum && q.yy > w.yy都成假,可如果q.yy == w.yy且q.num < w.num,顺序则会出问题,so,再加一条q.sum == w.sum 即可 
}
int main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>x>>y>>z;
        a[i].sum=x+y+z;
        a[i].yy=x;
        a[i].num=i;
    }
    sort(a+1,a+n+1,cmp);
    for(int i=1;i<=5;i++){
        cout<<a[i].num<<' '<<a[i].sum;
        cout<<endl; 
    }
    return 0;
}

|