PAT (Advanced Level) 1062. Talent and Virtue (25)

简单排序。题意较长。

#include<cstdio>
#include<cstring>
#include<cmath>
#include<queue>
#include<vector>
#include<string>
#include<stack>
#include<map>
#include<algorithm>
using namespace std;

struct X
{
    int id;
    int v,t;
    int f;
}s[100000+10],tmp[100000+10],Ans[100000+10];
int n,L,H;
int tot;

bool cmp(const X&a,const X&b)
{
    if(a.t+a.v==b.t+b.v&&a.v==b.v) return a.id<b.id;
    if(a.t+a.v==b.t+b.v) return a.v>b.v;
    return a.t+a.v>b.t+b.v;
}

int main()
{
    scanf("%d%d%d",&n,&L,&H);
    for(int i=1;i<=n;i++) scanf("%d%d%d",&s[i].id,&s[i].v,&s[i].t);
    for(int i=1;i<=n;i++) s[i].f=0;

    for(int i=1;i<=n;i++) if(s[i].t<L||s[i].v<L) s[i].f=1;

    tot=0;
    int ans=0;

    for(int i=1;i<=n;i++)
    {
        if(s[i].f==1) continue;
        if(s[i].t>=H&&s[i].v>=H)
        {

            tmp[tot++]=s[i];
            s[i].f=1;
        }
    }

    sort(tmp,tmp+tot,cmp);
    for(int i=0;i<tot;i++) Ans[ans++]=tmp[i];
    tot=0;

    for(int i=1;i<=n;i++)
    {
        if(s[i].f==1) continue;
        if(s[i].t<H&&s[i].v>=H)
        {

            tmp[tot++]=s[i];
            s[i].f=1;
        }
    }

    sort(tmp,tmp+tot,cmp);
    for(int i=0;i<tot;i++) Ans[ans++]=tmp[i];
    tot=0;

    for(int i=1;i<=n;i++)
    {
        if(s[i].f==1) continue;
        if(s[i].t<H&&s[i].v<H&&s[i].v>=s[i].t)
        {

            tmp[tot++]=s[i];
            s[i].f=1;
        }
    }

    sort(tmp,tmp+tot,cmp);
    for(int i=0;i<tot;i++) Ans[ans++]=tmp[i];
    tot=0;

    for(int i=1;i<=n;i++)
    {
        if(s[i].f==1) continue;

            tmp[tot++]=s[i];
            s[i].f=1;

    }

    sort(tmp,tmp+tot,cmp);
    for(int i=0;i<tot;i++) Ans[ans++]=tmp[i];
    tot=0;

    printf("%d\n",ans);
    for(int i=0;i<ans;i++)
    {
        printf("%08d %d %d\n",Ans[i].id,Ans[i].v,Ans[i].t);
    }
    return 0;
}
时间: 2024-08-27 05:34:18

PAT (Advanced Level) 1062. Talent and Virtue (25)的相关文章

1062. Talent and Virtue (25)【排序】——PAT (Advanced Level) Practise

题目信息 1062. Talent and Virtue (25) 时间限制200 ms 内存限制65536 kB 代码长度限制16000 B About 900 years ago, a Chinese philosopher Sima Guang wrote a history book in which he talked about people's talent and virtue. According to his theory, a man being outstanding i

PAT 1062. Talent and Virtue (25)

1062. Talent and Virtue (25) About 900 years ago, a Chinese philosopher Sima Guang wrote a history book in which he talked about people's talent and virtue. According to his theory, a man being outstanding in both talent and virtue must be a "sage(圣人

1062 Talent and Virtue (25)

1 /* 2 3 4 L (>=60), the lower bound of the qualified grades -- 5 that is, only the ones whose grades of talent and virtue are both not below 6 this line will be ranked; 7 8 and H (<100), the higher line of qualification 9 10 11 ,those with both gra

PAT Advanced Level 1013 Battle Over Cities (25)(25 分)

1013 Battle Over Cities (25)(25 分) It is vitally important to have all the cities connected by highways in a war. If a city is occupied by the enemy, all the highways from/toward that city are closed. We must know immediately if we need to repair any

PAT (Advanced Level) 1089. Insert or Merge (25)

简单题.模拟一下即可. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #include<map> #include<queue> #include<stack> #include<algorithm> using namespace std; const int maxn=200; int a[maxn],b[maxn],

PAT (Advanced Level) 1007. Maximum Subsequence Sum (25)

简单DP. 注意:If all the K numbers are negative, then its maximum sum is defined to be 0, and you are supposed to output the first and the last numbers of the whole sequence. #include<iostream> #include<cstring> #include<cmath> #include<al

PAT (Advanced Level) 1113. Integer Set Partition (25)

简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #include<map> #include<queue> #include<stack> #include<algorithm> using namespace std; long long a[100000+10]; long long sum=0,sum2; i

PAT (Advanced Level) 1040. Longest Symmetric String (25)

暴力. #include<cstdio> #include<cstring> #include<algorithm> using namespace std; char s[2000]; int ans,len,sum; void check(int a,int b) { if(s[a]!=s[b]) return; if(a==b) sum=1; else sum=2; int left=a-1,right=b+1; while(!(left<0||right&

PAT (Advanced Level) 1009. Product of Polynomials (25)

简单模拟. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> #include<cstdio> using namespace std; double a[3000],b[3000],c[3000]; int k; int main() { for(int i=0;i<=2000;i++) a[i]=b[i]=c[i]=0; int Max=-1