B1015 德才论 (25 分)

19/25

#include<bits/stdc++.h>
using namespace std;
/*
1.de>=H && cai>=H
2.de>=H && L<=cai<H
3.L=<de<H && L=<cai<H && de>=cai
4.L=<de<H && L=<cai<H && de<cai
*/

struct candidate{
    string code;
    int de;
    int cai;
    bool operator<(const candidate& can2){
        if((de+cai)==(can2.de+can2.cai)){
            if(de==can2.de)return code>can2.code;
            return de<can2.de;
        }
        return (de+cai)<(can2.de+can2.cai);
    }
};
vector<candidate> v[4];
int main(){
    int N,L,H;//L:low H:high
    cin>>N>>L>>H;
    int count=0;
    while(N--){
        candidate c;
        cin>>c.code>>c.de>>c.cai;
        if(c.de>=L && c.cai>=L){
            if(c.de>=H && c.cai>=H) v[0].push_back(c);
            else if(c.de>=H && c.cai<H) v[1].push_back(c);
            else if(c.de<H && c.cai<H){
                if(c.de>=c.cai)v[2].push_back(c);
                else v[3].push_back(c);
            }
            else{
                v[3].push_back(c);
            }
            count++;
        }
    }
    cout<<count<<endl;
    for(int i=0;i<4;i++){
        sort(v[i].begin(),v[i].end());
    }
    for(int i=0;i<4;i++){
        while(!v[i].empty()){
            cout<<v[i].back().code<<' '<<v[i].back().de<<' '<<v[i].back().cai<<endl;
            v[i].pop_back();
        }
    }
    return 0;
}

结果判定超时。看看原因是不是输出是cout的原因,换成printf看看。还确实是......看来不轻易用cout是真的。
25/25

#include<bits/stdc++.h>
using namespace std;
/*
1.de>=H && cai>=H
2.de>=H && L<=cai<H
3.L=<de<H && L=<cai<H && de>=cai
4.L=<de<H && L=<cai<H && de<cai
*/

struct candidate{
    string code;
    int de;
    int cai;
    bool operator<(const candidate& can2){
        if((de+cai)==(can2.de+can2.cai)){
            if(de==can2.de)return code>can2.code;
            return de<can2.de;
        }
        return (de+cai)<(can2.de+can2.cai);
    }
};
vector<candidate> v[4];
int main(){
    int N,L,H;//L:low H:high
    cin>>N>>L>>H;
    int count=0;
    while(N--){
        candidate c;
        cin>>c.code>>c.de>>c.cai;
        if(c.de>=L && c.cai>=L){
            if(c.de>=H && c.cai>=H) v[0].push_back(c);
            else if(c.de>=H && c.cai<H) v[1].push_back(c);
            else if(c.de<H && c.cai<H){
                if(c.de>=c.cai)v[2].push_back(c);
                else v[3].push_back(c);
            }
            else{
                v[3].push_back(c);
            }
            count++;
        }
    }
    printf("%d\n",count);
    for(int i=0;i<4;i++){
        sort(v[i].begin(),v[i].end());
    }
    for(int i=0;i<4;i++){
        while(!v[i].empty()){
            printf("%s %d %d\n",v[i].back().code.c_str(),v[i].back().de,v[i].back().cai);
            v[i].pop_back();
        }
    }
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/MarkKobs-blog/p/10559587.html