70分求助

P1093 [NOIP2007 普及组] 奖学金

ge_yiyang_001_DT @ 2023-08-17 15:26:04


#include<iostream>
using namespace std;
int n;
struct node{
    int mz,zf,yw;
}a[305],b[305];
void quicksort(int l,int r){
    if(l==r)return;
    int mid=(l+r)/2;
    quicksort(l,mid);
    quicksort(mid+1,r);
    int i=l,j=mid+1,k=0;
    while(i<=mid&&j<=r){
        if(a[i].zf>a[j].zf||(a[i].zf==a[j].zf&&a[i].yw>a[j].yw||(a[i].yw==a[j].yw&&a[i].mz<a[j].mz))){
            b[++k]=a[i++];
        }
        else{
            b[++k]=a[j++];
        }
    }
    while(i<=mid)b[++k]=a[i++];
    while(j<=r)b[++k]=a[j++];
    for(int i=l;i<=r;i++){
        a[i]=b[i-l+1];
    }
    return;
}
int main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        int sx,yy;
        a[i].mz=i;
        cin>>a[i].yw>>sx>>yy;
        a[i].zf=a[i].yw+sx+yy;
    }
    quicksort(1,n);
    for(int i=1;i<=5;i++){
        cout<<a[i].mz<<' '<<a[i].zf<<endl;
    }
    return 0;
}

by ge_yiyang_001_DT @ 2023-08-17 15:26:53

归并排序


by ge_yiyang_001_DT @ 2023-08-18 14:57:08

是不是没人想看我的归并排序啊


by ge_yiyang_001_DT @ 2023-08-18 14:59:04

我知道sort很简单,但是我们老师要求我们用归并


|