PAT (Advanced Level) 1012. The Best Rank (25)

简单排序题。

注意:分数相同的人排名相同。

#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<map>
using namespace std;

struct X
{
    int k;
    int id;
    int f1,f2,f3,f4;
    int r[6];
}s[5000];
int n,m;
map<int,int>z;

int get(int a,int b,int c)
{
    double sum=1.0*a+1.0*b+1.0*c;
    sum=sum/3+0.5;
    int res=(int)sum;
    return res;
}

bool cmp1(const X&a,const X&b){return a.f1>b.f1;}
bool cmp2(const X&a,const X&b){return a.f2>b.f2;}
bool cmp3(const X&a,const X&b){return a.f3>b.f3;}
bool cmp4(const X&a,const X&b){return a.f4>b.f4;}
bool cmp5(const X&a,const X&b){return a.k<b.k;}

int main()
{
    scanf("%d%d",&n,&m); z.clear();
    for(int i=1;i<=n;i++)
    {
        scanf("%d%d%d%d",&s[i].id,&s[i].f2,&s[i].f3,&s[i].f4);
        s[i].f1=get(s[i].f2,s[i].f3,s[i].f4);
        z[s[i].id]=i;
        s[i].k=i;
    }

    s[0].f1=s[0].f2=s[0].f3=s[0].f4=-456;

    sort(s+1,s+1+n,cmp1);
    for(int i=1;i<=n;i++)
    {
        if(s[i].f1==s[i-1].f1) s[i].r[1]=s[i-1].r[1];
        else s[i].r[1]=i;
    }

    sort(s+1,s+1+n,cmp2);
    for(int i=1;i<=n;i++)
    {
        if(s[i].f2==s[i-1].f2) s[i].r[2]=s[i-1].r[2];
        else s[i].r[2]=i;
    }

    sort(s+1,s+1+n,cmp3);
    for(int i=1;i<=n;i++)
    {
        if(s[i].f3==s[i-1].f3) s[i].r[3]=s[i-1].r[3];
        else s[i].r[3]=i;
    }

    sort(s+1,s+1+n,cmp4);
    for(int i=1;i<=n;i++)
    {
        if(s[i].f4==s[i-1].f4) s[i].r[4]=s[i-1].r[4];
        else s[i].r[4]=i;
    }

    sort(s+1,s+1+n,cmp5);

    for(int i=1;i<=m;i++)
    {
        int id; scanf("%d",&id);
        if(z[id]==0) printf("N/A\n");
        else
        {
            int Min=9999;
            for(int j=1;j<=4;j++)
                Min=min(Min,s[z[id]].r[j]);
            for(int j=1;j<=4;j++)
            {
                if(s[z[id]].r[j]==Min)
                {
                    printf("%d ",Min);
                    if(j==1) printf("A\n");
                    if(j==2) printf("C\n");
                    if(j==3) printf("M\n");
                    if(j==4) printf("E\n");
                    break;
                }
            }
        }
    }
    return 0;
}
时间: 2024-07-30 10:21:15

PAT (Advanced Level) 1012. The Best Rank (25)的相关文章

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

PAT (Advanced Level) 1094. The Largest Generation (25)

简单DFS. #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<map> #include<queue> #include<stack> #include<vector> using namespace std; const int maxn=200; int n,m; vector<int>

PAT (Advanced Level) 1074. Reversing Linked List (25)

简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #include<map> #include<stack> #include<queue> #include<string> #include<algorithm> using namespace std; const int maxn=100000+10

PAT (Advanced Level) 1110. Complete Binary Tree (25)

判断一棵二叉树是否完全二叉树. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #include<map> #include<queue> #include<stack> #include<algorithm> using namespace std; int n,root; const int maxn=30; struc