1080. Graduate Admission (30)

来源:互联网 发布:《java开发实战经典》 编辑:程序博客网 时间:2024/06/05 09:17

排序好,好排名,然后按排名靠前到靠后的顺序依次处理

#include<iostream>#include<vector>#include<algorithm>#pragma warning(disable:4996)using namespace std;struct node {//输入节点    int id;    int ge, gi, sum;    vector<int> sc;    int rank;    bool operator<(const node that)const {        return sum > that.sum ||            (sum == that.sum && ge > that.ge);    }};int  N, M, K;vector<int> school;//存储学校/专业要的人数vector<node> all;//存储所有输入vector<vector<int>> re;//结果vector<int> ra;//存储过程中各个学校最后一名的rankint main(){    cin >> N >> M >> K;    school.resize(M);    all.resize(N);    re.resize(M);    ra.resize(M);    for (int t = 0;t < M;t++)        cin >> school[t];    for (int t = 0;t < N;t++)//存储输入    {        all[t].id = t;        scanf("%d %d", &all[t].ge, &all[t].gi);        //cin >> all[t].ge >> all[t].gi;        for (int i = 0;i < K;i++) {            int aa;            scanf("%d", &aa);            //cin >> aa;            all[t].sc.push_back(aa);            if (getchar() == '\n') break;        }        all[t].sum = all[t].ge + all[t].gi;    }    sort(all.begin(), all.end());//排序    all[0].rank = 1;    for (int t = 1;t < N;t++)//计算rank        if (all[t].sum == all[t - 1].sum && all[t].ge == all[t - 1].ge) all[t].rank = all[t - 1].rank;        else all[t].rank = t+1;    for (auto x : all)//按排名对每一个学生进行处理    {        for (auto y : x.sc)            if (re[y].size() < school[y] ||ra[y] == x.rank) {                re[y].push_back(x.id);ra[y] = x.rank;break;            }    }    for (auto &x : re)//输出结果    {        sort(x.begin(), x.end());        int f = 1;        for (auto y : x)            if (f == 1) {                printf("%d", y);f = 0;            }            else                printf(" %d", y);        cout << endl;    }}
0 0
原创粉丝点击