zoukankan      html  css  js  c++  java
  • PAT甲题题解-1062. Talent and Virtue (25)-排序水题

    水题,分组排序即可。

    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <string.h>
    
    using namespace std;
    /*
    太水水水。。。
    */
    const int maxn=100000+5;
    int cnt1,cnt2,cnt3,cnt4;
    struct Node{
        int id;
        int tot;
        int vir;
        int tal;
        bool operator<(const Node tmp)const{
            if(tot==tmp.tot){
                if(vir==tmp.vir)
                    return id<tmp.id;
                else
                    return vir>tmp.vir;
            }
            else
                return tot>tmp.tot;
    
        }
    }sages[maxn],noble[maxn],fool[maxn],small[maxn];
    
    int main()
    {
        int n,L,H;
        int a,b,c;
        scanf("%d %d %d",&n,&L,&H);
        for(int i=1;i<=n;i++){
            scanf("%d %d %d",&a,&b,&c);
            if(b<L || c<L)
                continue;
            if(b>=H && c>=H){
                sages[cnt1].id=a;
                sages[cnt1].vir=b;
                sages[cnt1].tal=c;
                sages[cnt1].tot=b+c;
                cnt1++;
            }
            else if(b>=H && c<H && c>=L){
                noble[cnt2].id=a;
                noble[cnt2].vir=b;
                noble[cnt2].tal=c;
                noble[cnt2].tot=b+c;
                cnt2++;
            }
            else if(b<H && c<H &&b>=c){
                fool[cnt3].id=a;
                fool[cnt3].vir=b;
                fool[cnt3].tal=c;
                fool[cnt3].tot=b+c;
                cnt3++;
            }
            else{
                small[cnt4].id=a;
                small[cnt4].vir=b;
                small[cnt4].tal=c;
                small[cnt4].tot=b+c;
                cnt4++;
            }
        }
        sort(sages,sages+cnt1);
        sort(noble,noble+cnt2);
        sort(fool,fool+cnt3);
        sort(small,small+cnt4);
        printf("%d
    ",cnt1+cnt2+cnt3+cnt4);
        for(int i=0;i<cnt1;i++){
            printf("%08d %d %d
    ",sages[i].id,sages[i].vir,sages[i].tal);
        }
        for(int i=0;i<cnt2;i++){
            printf("%08d %d %d
    ",noble[i].id,noble[i].vir,noble[i].tal);
        }
        for(int i=0;i<cnt3;i++){
            printf("%08d %d %d
    ",fool[i].id,fool[i].vir,fool[i].tal);
        }
        for(int i=0;i<cnt4;i++){
            printf("%08d %d %d
    ",small[i].id,small[i].vir,small[i].tal);
        }
        return 0;
    }
    View Code
  • 相关阅读:
    【UNR #1】火车管理
    NOIP2018保卫王国
    [SCOI2015]国旗计划[Wf2014]Surveillance
    [TJOI2015]线性代数(最小割)
    [AH2017/HNOI2017]礼物(FFT)
    BZOJ5093图的价值(斯特林数)
    [NOI2018]你的名字(后缀自动机+线段树)
    [SDOI2015]序列统计(多项式快速幂)
    [NOI2014]购票(斜率优化+线段树)
    [CQOI2017]小Q的表格(数论+分块)
  • 原文地址:https://www.cnblogs.com/chenxiwenruo/p/6497015.html
Copyright © 2011-2022 走看看