PAT (Advanced Level) 1055. The World's Richest (25)

排序。随便加点优化就能过。

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

struct X
{
    char name[10];
    int age;
    int val;
}s[100000+10];
int n,k,cnt;
int ans[100000+10];

bool cmp(const int &a,const int &b)
{
    if(s[a].val==s[b].val&&s[a].age==s[b].age)
        return strcmp(s[a].name,s[b].name)<0;
    if(s[a].val==s[b].val) return s[a].age<s[b].age;
    return s[a].val>s[b].val;
}

bool CMP(const X&a,const X&b)
{
    if(a.val==b.val&&a.age==b.age)
        return strcmp(a.name,b.name)<0;
    if(a.val==b.val) return a.age<b.age;
    return a.val>b.val;
}

int main()
{
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++)
        scanf("%s%d%d",s[i].name,&s[i].age,&s[i].val);
    sort(s+1,s+1+n,CMP);
    for(int i=1;i<=k;i++)
    {
        int a,b,c; scanf("%d%d%d",&a,&b,&c);
        cnt=0;
        for(int j=1;j<=n;j++){
            if(s[j].age>=b&&s[j].age<=c) ans[cnt++]=j;
            if(cnt==a) break;
        }
        printf("Case #%d:\n",i);
        if(cnt==0) printf("None\n");
        else
        {
            sort(ans,ans+cnt,cmp);
            for(int j=0;j<min(a,cnt);j++)
                printf("%s %d %d\n",s[ans[j]].name,s[ans[j]].age,s[ans[j]].val);
        }
    }
    return 0;
}

  

PAT (Advanced Level) 1055. The World's Richest (25)

时间: 2024-10-05 18:19:56

PAT (Advanced Level) 1055. The World's Richest (25)的相关文章

PAT (Advanced Level) 1082. Read Number in Chinese (25)

模拟题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #include<map> #include<stack> #include<queue> #include<string> #include<iostream> #include<algorithm> using namespace std;

PAT (Advanced Level) 1039. Course List for Student (25)

map会超时,二分吧... #include<iostream> #include<cstring> #include<cmath> #include<algorithm> #include<cstdio> #include<map> #include<queue> #include<string> #include<vector> using namespace std; int n,m; int

PAT (Advanced Level) 1002. A+B for Polynomials (25)

为0的不要输出. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> #include<cstdio> using namespace std; double a[1500],b[1500]; int k; int main() { for(int i=0;i<=1000;i++) a[i]=b[i]=0; int Max=-1; scanf(&q

PAT (Advanced Level) 1102. Invert a Binary Tree (25)

简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #include<map> #include<queue> #include<stack> #include<algorithm> using namespace std; struct Node { int left; int right; }s[20]; int

PAT (Advanced Level) 1098. Insertion or Heap Sort (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[m

PAT (Advanced Level) 1066. Root of AVL Tree (25)

AVL树的旋转.居然1A了.... 了解旋转方式之后,数据较小可以当做模拟写. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #include<map> #include<stack> #include<queue> #include<string> #include<algorithm> using name

PAT (Advanced Level) 1067. Sort with Swap(0,*) (25)

只对没有归位的数进行交换. 分两种情况: 如果0在最前面,那么随便拿一个没有归位的数和0交换位置. 如果0不在最前面,那么必然可以归位一个数字,将那个数字归位. 这样模拟一下即可. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #include<map> #include<stack> #include<queue> #include

PAT Advanced 1055 The World&#39;s Richest (25分)

Forbes magazine publishes every year its list of billionaires based on the annual ranking of the world's wealthiest people. Now you are supposed to simulate this job, but concentrate only on the people in a certain range of ages. That is, given the n

PAT:1055. The World&#39;s Richest (25) AC

#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; struct Person { char name[10]; int age,money; }P[100010]; bool cmp(Person a,Person b) { if(a.money!=b.money) return a.money>b.money; else if(a.age!=b.age) r