为什么错

P1093 [NOIP2007 普及组] 奖学金

dyzxjzx @ 2017-08-21 22:43:56

#include<bits/stdc++.h>
using namespace std;
struct qs
{
    int yu;
    int shu;
    int ying;
    int n;
}a[300];
void qsort(int left,int right)
{
    if(left==right)return;
    int mid=(left+right)/2;
    int i=left,j=right;
    while(i<=j)
    {
        while((a[i].yu+a[i].shu+a[i].ying>a[mid].yu+a[mid].shu+a[mid].ying)||(a[i].yu+a[i].shu+a[i].ying==a[mid].yu+a[mid].shu+a[mid].ying&&a[i].yu>a[mid].yu)||(a[i].yu+a[i].shu+a[i].ying==a[mid].yu+a[mid].shu+a[mid].ying&&a[i].yu==a[mid].yu&&a[i].n<a[mid].n))i++;
        while((a[j].yu+a[j].shu+a[j].ying<a[mid].yu+a[mid].shu+a[mid].ying)||(a[j].yu+a[j].shu+a[j].ying==a[mid].yu+a[mid].shu+a[mid].ying&&a[j].yu<a[mid].yu)||(a[j].yu+a[j].shu+a[j].ying==a[mid].yu+a[mid].shu+a[mid].ying&&a[j].yu==a[mid].yu&&a[j].n>a[mid].n))j--;
        if(i<=j)
        {
            qs tmp=a[i];
            a[i]=a[j];
            a[j]=tmp;
            i++;j--;
        }
    }
    if(i<right)qsort(i,right);
    if(left<j)qsort(left,j);
    return;
}
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++){a[i].n=i+1;cin>>a[i].yu>>a[i].shu>>a[i].ying;}
    qsort(0,n-1);
    for(int i=0;i<5;i++)cout<<a[i].n<<" "<<a[i].yu+a[i].shu+a[i].ying<<endl;
}

by 縱橫依舊 @ 2017-09-16 14:50:32

方法错了吧,多关键字排序


|