PAT A1080 题解

#include<bits/stdc++.h>
using namespace std;

struct Apply
{
    int grade_e;
    int grade_i;
    int total_grade;
    int choices[5];
    int Rank;
    int num;
}a[40000];

struct School
{
    int quote;
    int con = 0;
    int students[40000];
}s[100];

bool cmp(Apply a1, Apply a2)
{
    if (a1.total_grade != a2.total_grade)
        return a1.total_grade > a2.total_grade;
    else
        return a1.grade_e > a2.grade_e;
}

int main()
{
    int n, m, k;
    cin >> n >> m >> k;
    for(int i = 0; i < m; i++)
        scanf("%d", &s[i].quote);
    for(int i = 0; i < n; i++)
    {
        scanf("%d %d",&a[i].grade_e, &a[i].grade_i);
        a[i].total_grade = a[i].grade_e + a[i].grade_i;
        a[i].num = i;
        for(int ii = 0; ii < k; ii++)
            scanf("%d", &a[i].choices[ii]);
    }
    sort(a, a + n, cmp);
    a[0].Rank = 1;
    for(int i = 1; i < n; i++)
    {
        if (a[i].total_grade != a[i - 1].total_grade)
            a[i].Rank = i + 1;
        else
        {
            if(a[i].grade_e != a[i - 1].grade_e)
                a[i].Rank = i + 1;
            else
                a[i].Rank = a[i - 1].Rank;
        }
    }
    int last_ad;
    for(int i = 0; i < n; i++)
    {
        for(int ii = 0; ii < k; ii++)
        {
            int c = a[i].choices[ii];
            if ((s[c].con < s[c].quote) || (a[i].Rank == a[i - 1].Rank && c == last_ad))
            {
                s[c].students[s[c].con] = a[i].num;
                s[c].con++;
                last_ad = c;
                break;
            }
        }
    }
    for(int i = 0; i < m; i++)
    {
        if (s[i].con > 0)
        {
            sort(s[i].students, s[i].students + s[i].con);
            for(int ii = 0; ii < s[i].con; ii++)
            {
                printf("%d", s[i].students[ii]);
                if (ii != s[i].con - 1)
                    printf(" ");
            }
            printf("\n");
        }
        else
            printf("\n");
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值