zoukankan      html  css  js  c++  java
  • 1080 Graduate Admission (30 分)(排序)【回顾】

    It is said that in 2013, there were about 100 graduate schools ready to proceed over 40,000 applications in Zhejiang Province. It would help a lot if you could write a program to automate the admission procedure.

    Each applicant will have to provide two grades: the national entrance exam grade GE, and the interview grade GI. The final grade of an applicant is (GE + GI) / 2. The admission rules are:

    The applicants are ranked according to their final grades, and will be admitted one by one from the top of the rank list.
    If there is a tied final grade, the applicants will be ranked according to their national entrance exam grade GE. If still tied, their ranks must be the same.
    Each applicant may have K choices and the admission will be done according to his/her choices: if according to the rank list, it is one's turn to be admitted; and if the quota of one's most preferred shcool is not exceeded, then one will be admitted to this school, or one's other choices will be considered one by one in order. If one gets rejected by all of preferred schools, then this unfortunate applicant will be rejected.
    If there is a tied rank, and if the corresponding applicants are applying to the same school, then that school must admit all the applicants with the same rank, even if its quota will be exceeded.

    Input Specification:

    Each input file contains one test case. Each case starts with a line containing three positive integers: N (<=40,000), the total number of applicants; M (<=100), the total number of graduate schools; and K (<=5), the number of choices an applicant may have.

    In the next line, separated by a space, there are M positive integers. The i-th integer is the quota of the i-th graduate school respectively.

    Then N lines follow, each contains 2+K integers separated by a space. The first 2 integers are the applicant's GE and GI, respectively. The next K integers represent the preferred schools. For the sake of simplicity, we assume that the schools are numbered from 0 to M-1, and the applicants are numbered from 0 to N-1.

    Output Specification:

    For each test case you should output the admission results for all the graduate schools. The results of each school must occupy a line, which contains the applicants' numbers that school admits. The numbers must be in increasing order and be separated by a space. There must be no extra space at the end of each line. If no applicant is admitted by a school, you must output an empty line correspondingly.

    Sample Input:

    11 6 3
    2 1 2 2 2 3
    100 100 0 1 2
    60 60 2 3 5
    100 90 0 3 4
    90 100 1 2 0
    90 90 5 1 3
    80 90 1 0 2
    80 80 0 1 2
    80 80 0 1 2
    80 70 1 3 2
    70 80 1 2 3
    100 100 0 2 4

    Sample Output:

    0 10
    3
    5 6 7
    2 8

    1 4

    生词

    英文 解释
    Graduate Admission 研究生入学
    automate 使自动化
    quota 限额

    分析:

    1.设立stu结构体,存储学生的id(防止排序后id打乱了顺序),GE和GI的成绩,总评成绩,排名,志愿学校的列表数组。
    2.设立sch结构体,存储school[i]招生的名额限制maxNum,现在已经招收了的学生个数nowNum,招收的学生的id列表stuID,以及当前已经招收了的学生的排名的最后一名lastRank。
    3.把学生按照成绩进行排序,并赋值排名。如果GE一样且Grade一样,他们的名次就是一样的。
    4.从第一个学生开始,根据他的志愿,来尝试被学校录取。如果当前学校名额未满。那么就录取进去,并且让学校的nowNum加1.并且更新lastRank为这个学生的rank。如果当前学校的lastRank等于自己的rank,那么不管名额满不满都录取。而且记得把学生的id添加到学校的stuID列表中。

    5.输出的时候因为id顺序是乱的,要先从小到大排序,然后输出。每个学校占一行、

    原文链接:https://blog.csdn.net/liuchuo/article/details/52493707

    题解

    这里用的存放 学校录取的学生列表 结构些许复杂,拆开看一下:

    sch[0]					sch[1]
    	0:stu.id=0				0:stu.id=3
    	1:stu.id=10	
    
    sch[2]					sch[4]
    	0:stu.id=5				null
    	1:stu.id=6
    	2:stu.id=7
    

    上面是根据学生id排序后的sch数组,他的每一个元素是一个vector<peo>,下面举例说明一下如果两个学生的fin与ge成绩都相同是如何比较的:

    stu[i].fin==sch[schid][lastindex].fin && stu[i].ge==sch[schid][lastindex].ge

    1.先定位到sch[schid],然后它是一个vector<peo>向量嘛;

    2.接下来定位到他的最后一名学生那个结构体,比如sch[0][1],他就是10号学生;

    3.之后找到他的fin成绩,与当前学生stu[i].fin进行比较;

    4.同理,ge成绩也是这样找的。

    #include <bits/stdc++.h>
    
    using namespace std;
    struct peo
    {
        int id,ge,gi,fin;
        vector<int> choice;
    };
    bool cmp(peo a,peo b){
        if(a.fin!=b.fin) return a.fin>b.fin;
        return a.ge>b.ge;
    }
    bool cmp1(peo a,peo b){
        return a.id<b.id;
    }
    int main()
    {
    #ifdef ONLINE_JUDGE
    #else
        freopen("1.txt", "r", stdin);
    #endif
        int n,m,k,quota[110],cnt[110]={0};
        cin>>n>>m>>k;
        vector<peo> stu(n),sch[110];
        for(int i=0;i<m;i++){
            cin>>quota[i];
        }
        for(int i=0;i<n;i++){
            cin>>stu[i].ge>>stu[i].gi;
            stu[i].id=i;
            stu[i].fin=stu[i].ge+stu[i].gi;
            stu[i].choice.resize(k);
            for(int j=0;j<k;j++){
                cin>>stu[i].choice[j];
            }
        }
        sort(stu.begin(),stu.end(),cmp);
        for(int i=0;i<n;i++){
            for(int j=0;j<k;j++){
                int schid=stu[i].choice[j];
                int lastindex=cnt[schid]-1;
                if(cnt[schid]<quota[schid]||stu[i].fin==sch[schid][lastindex].fin && stu[i].ge==sch[schid][lastindex].ge){
                    sch[schid].push_back(stu[i]);
                    cnt[schid]++;
                    break;
                }
            }
        }
        for(int i=0;i<m;i++){
            sort(sch[i].begin(),sch[i].end(),cmp1);
            for(int j=0;j<cnt[i];j++){
                if(j!=0) cout<<" ";
                cout<<sch[i][j].id;
            }
            cout<<endl;
        }
        return 0;
    }
    
  • 相关阅读:
    Velocity 创建命令缓存
    关于RESTful Web Services和RESTful设计的一些文章
    [转]Restful Web Services浅析
    Silverlight点滴(四)Silverlight访问Web Service报"System.Security.SecurityException: 安全性错误"的处理
    WebDevHelper RESTful服务和Ajax开发时的利器
    [原]读Google Data API源代码一:从创建一个日历(Calendar)开始
    [转]使用 WCF 和 .NET Framework 3.5 进行 HTTP 编程
    [原]Silverlight3 支持所有HTTP方法
    [原]RESTful Web Service之以HTTP PUT方式调用WCF服务
    [原]Google API学习2:Google API稍深入一步
  • 原文地址:https://www.cnblogs.com/moonlight1999/p/15718979.html
Copyright © 2011-2022 走看看