蒟蒻求助!! 50分

P1093 [NOIP2007 普及组] 奖学金

MrChensu @ 2021-08-07 16:16:37

#include<iostream>
#include<algorithm>
using namespace std;
struct gr{
    long long y,s,e,sum,id;
}peo[310];
bool cmp(gr a,gr b){
    return a.sum>b.sum;
}
bool cmp1(gr a,gr b){
    return a.y>b.y;
}
bool cmp2(gr a,gr b){
    return a.id<b.id;
}
int main(){
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        peo[i].id=i+1;
        cin>>peo[i].y>>peo[i].s>>peo[i].e;
        peo[i].sum=peo[i].y+peo[i].s+peo[i].e;
    }
    sort(peo,peo+n,cmp);
    gr ans[20];
    for(int i=0;i<5;i++){
        ans[i]=peo[i];
    }
    gr flag;
    flag=ans[0];
    int count[20]={0};
    int a=0;
    bool f=false;
    if(flag.sum==ans[1].sum){
            count[0]=0;
            a++;
            f=true;
    }
    for(int i=1;i<5;i++){
        if(flag.sum==ans[i].sum){
            count[a]=i;
            a++;
            f=true;
        }
        flag=ans[i];
    }
    if(f){
        sort(ans+count[0],ans+count[a-1],cmp1);
        f=false;
        flag=ans[count[0]];
        int h,j;
        h=count[0];
        j=a+1;
        a=0;
        int count[20]={0};
        for(int i=h;i<j;i++){
            if(flag.y==ans[i].y){
                count[a]=i;
                a++;
                f=true;
            }
            flag=ans[i];
        }
        if(f){
            sort(ans+count[0],ans+count[a-1],cmp2);
        }
    }
    for(int i=0;i<5;i++){
        cout<<ans[i].id<<" "<<ans[i].sum<<"\n";
    }
    return 0;
}

by MrChensu @ 2021-08-07 16:17:16

后五个样例过不了


by k090218 @ 2021-08-07 16:27:42

emm


by MrChensu @ 2021-08-08 10:22:16

终于,换了种方法AC了


|