• 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 G~E~, and the interview grade G~I~. The final grade of an applicant is (G~E~ + G~I~) / 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 G~E~. 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 G~E~ and G~I~, 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

    题目大意:将每个学生按照成绩排序,然后根据学生的意向学校去投递, 如果意向学校已经满了,继续投递; 输出每个学校录取的学生编号
    思路:建立两个struct, sch:记录学校要录取的人数, 最后一个录取学生的名次, 以及录取学生的数组; node:记录学生的成绩,编号,意向学校;
        通过学生成绩依次按照每个学生的意向学校去探测意向学校是否能投递, 能投递则把学生添加到相应的学校中, 对每个学校录取的学生排序后输出;
    注意点:1.对于需要排序的结构数据,一般应该在结构中记录数据的编号; 2.正确放置break点

     1  #include<iostream>
     2 #include<algorithm>
     3 #include<vector>
     4 #include<set>
     5 using namespace std;
     6 struct Stu{
     7   int ge, gi, gf, rank;
     8   int id;
     9   int choice[5];
    10 };
    11 struct Sch{
    12   int maxn, lastrank;
    13   set<int> admit;
    14 };
    15 bool cmp(Stu& a, Stu& b){
    16   if(a.gf!=b.gf) return a.gf>b.gf;
    17   return a.ge>b.ge;
    18 }
    19 int main(){
    20   int n, m, k, i, j;
    21   scanf("%d%d%d", &n, &m, &k);
    22   vector<Sch> sch(m);
    23   vector<Stu> stu(n);
    24   for(i=0; i<m; i++) scanf("%d", &sch[i].maxn);
    25   for(i=0; i<n; i++){
    26     scanf("%d%d", &stu[i].ge, &stu[i].gi);
    27     stu[i].gf = (stu[i].gi+stu[i].ge)/2;
    28       stu[i].id=i;//排序过后  位置会改变 要设置一个变量来保存序号
    29     for(j=0; j<k; j++) scanf("%d", &stu[i].choice[j]);
    30   }
    31   sort(stu.begin(), stu.end(), cmp);
    32   int rank = 1;
    33   for(i=0; i<n; i++){//确定名次
    34     if(i==0 || (stu[i].gf==stu[i-1].gf && stu[i].gi==stu[i-1].gi)) stu[i].rank = rank;
    35     else{
    36       rank = i+1;
    37       stu[i].rank = rank;
    38     }
    39   }
    40   for(i=0; i<n; i++){
    41     bool flag=false;
    42     for(j=0; j<k; j++){
    43       int schid = stu[i].choice[j];
    44       if(sch[schid].maxn>0){
    45         sch[schid].admit.insert(stu[i].id);
    46         sch[schid].maxn--;
    47         sch[schid].lastrank = stu[i].rank;
    48             flag = true;
    49         }else if(sch[schid].lastrank==stu[i].rank) {
    50             sch[schid].admit.insert(stu[i].id);
    51             flag = true;
    52         }//记得投递成功后, 退出循环 否则会多次循环
    53       if(flag) break;
    54     }
    55   }
    56   for(i=0; i<m; i++){
    57     set<int>::iterator it = sch[i].admit.begin();
    58     for(; it!=sch[i].admit.end(); it++){
    59       if(it == sch[i].admit.begin()) printf("%d", *it);
    60       else printf(" %d", *it);
    61     }
    62     printf("
    ");
    63   }
    64   return 0;
    65 }
    有疑惑或者更好的解决方法的朋友,可以联系我,大家一起探讨。qq:1546431565
  • 相关阅读:
    java PKCS7Padding 加密Cannot find any provider supporting AES/CBC/PKCS7Padding 解决办法
    win7系统c盘瘦身,去虚拟内存方式
    跟据经纬度实现附近搜索Java实现
    Java 406
    window.showModalDialog 子窗口和父窗口不兼容最新的谷歌
    <html:text> Id属性
    Unity3D GUI学习之GUI窗口的使用
    Unity3D GUI学习之GUILayout控件及使用
    Unity3D GUI之自定义风格组件
    Unity3D GUI学习
  • 原文地址:https://www.cnblogs.com/mr-stn/p/9182384.html
Copyright © 2020-2023  润新知