码迷,mamicode.com
首页 > 其他好文 > 详细

题目1005:Graduate Admission

时间:2014-07-21 00:12:54      阅读:404      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   color   strong   os   

题目描述:

    It is said that in 2011, there are 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.

输入:

    Each input file may contain more than 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.

输出:

    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.

样例输入:
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
样例输出:
0 10
3
5 6 7
2 8

1 4

-------------------------------------------------------------------------------------------------------

思路:

  • 存储多组数据用数组,而且每个数组里面又包含不同类型的数据(比如最终成绩是两个整形成绩的平均,结果为浮点数),不同数据具有不同的含义,可用结构体数组使代码清晰明了~
  • 主要是一个以最终成绩对学生进行排序和选学校的过程

-------------------------------------------------------------------------------------------------------

  1 #include<stdio.h>
  2 #define N 400//按题目要求的40000会超过内存限制~小一点就行
  3 #define M 100
  4 #define K 5
  5 struct appli{
  6     int b;//编号
  7     int ge;//ge成绩
  8     int gi;//gi成绩
  9     float sco;//最终成绩
 10     int s[K];//报考学校编号
 11 }A[N],t;
 12 struct school{
 13     int z;//招的人数
 14     int y;//已招人数
 15     struct appli a[N];//存录取学生信息
 16 }S[M];
 17 int main(int argc, char const *argv[])
 18 {
 19     int n,m,k; 
 20     int i,j,t1;
 21     int cout;
 22     int flag; 24     while(scanf("%d %d %d",&n,&m,&k)!=EOF)
 25     {
 26         for(i=0;i<m;i++)
 27         {
 28             scanf("%d",&S[i].z);//读入每所学校招的人数
 29             S[i].y=0;//当前招生人数初始为0
 30 
 31         }
 32         for(i=0;i<n;i++)
 33         {
 34             A[i].b=i;//设置每个学生的编号
 35             scanf("%d %d",&A[i].ge,&A[i].gi);//输入GE、GI
 36             for(j=0;j<k;j++)
 37             {
 38                     scanf("%d",&A[i].s[j]);//学生所选学校的编号 41             }
 42             A[i].sco=(float)((A[i].ge+A[i].gi)/2.0);
 43         }
 44         for(i=0;i<n-1;i++)//以最终成绩为标准对学生进行排序
 45         {
 46             for(j=i+1;j<n;j++)
 47             {
 48                 if(A[i].sco<A[j].sco||(A[i].ge<A[j].ge&&A[i].sco==A[j].sco))
 49                 {
 50                         t=A[i];
 51                         A[i]=A[j];
 52                         A[j]=t;
 53                 }
 54                 else
 55                     continue;
 56             }
 57         }
 58         for(i=0;i<n;i++)
 59         {
 60             flag=1;
 61             for(j=0;j<k&&flag;j++)
 62             {
 63                 if(S[A[i].s[j]].z>S[A[i].s[j]].y)
 64                 {
 65                     S[A[i].s[j]].a[S[A[i].s[j]].y]=A[i];
 66                     S[A[i].s[j]].y++;//已招人数+1
 67                     flag=0;
 68                 }
 69                 else
 70                 {
 71                     t=S[A[i].s[j]].a[S[A[i].s[j]].y-1];//该学校上次招的学生
 72                     if(t.sco==A[i].sco&&t.ge==A[i].ge)
 73                         {
 74                             S[A[i].s[j]].a[S[A[i].s[j]].y]=A[i];
 75                             S[A[i].s[j]].y++;//已招人数+1
 76                             flag=0;
 77                         }
 78                     else
 79                         continue;
 80                 }
 81             }
 82         } 
84
for(i=0;i<m;i++) 85 { 86 for(j=0;j<S[i].y-1;j++) 87 { 88 for(k=j+1;k<S[i].y;k++) 89 { 90 if(S[i].a[j].b>S[i].a[k].b) 91 { 92 t1=S[i].a[j].b; 93 S[i].a[j].b=S[i].a[k].b; 94 S[i].a[k].b=t1; 95 } 96 } 97 } 98 } 99 for(i=0;i<m;i++) 100 { 101 cout=0; 102 for(j=0;j<S[i].y;j++) 103 { 104 if(cout!=0) 105 printf(" "); 106 printf("%d",S[i].a[j].b); 107 cout++; 108 } 109 printf("\n"); 110 } 111 112 } 113 return 0; 114 }

题目1005:Graduate Admission,布布扣,bubuko.com

题目1005:Graduate Admission

标签:des   style   blog   color   strong   os   

原文地址:http://www.cnblogs.com/qq1029579233/p/3857304.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!