`
844604778
  • 浏览: 548828 次
文章分类
社区版块
存档分类
最新评论

题目1005: Graduate Admission (九度Online Judge)

 
阅读更多

题目1005: Graduate Admission (九度Online Judge)

1,真题


题目1005:Graduate Admission

时间限制:1 秒

内存限制:32 兆

特殊判题:

提交:3444

解决:954

题目描述:

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 thanone 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
来源:
2011年浙江大学计算机及软件工程研究生机试真题


2,分析


这个题信息很多,有点难。反正我是理了很久才弄明白的
题目意思是根据考生的排名来录取 ,简单的说是先给考生排名,然后从最高分开始录取,如果该考生的第一自愿学校已经录满,则看其第二自愿 。和我们高考的模式有点不一样 我在这儿纠结了很久


3,答案


import java.io.BufferedInputStream;
import java.util.Arrays;
import java.util.Scanner;
/**
 * to test problem_1005
 * @author Sunkun
 * Date: 2013.09.28
 * Memory: 18848KB
 * Code Length: 5294B	
 * Time Consuming: 120MS
 */
public class problem_1005 {
        private static Scanner in = new Scanner(new BufferedInputStream(System.in));

        private static class Student implements Comparable<Student> {
                int GE;
                int GI;
                int rank;
                int no;
                int AllChoice[];
                int TheSchool;

                public Student(int GE, int Gi, int no) {
                        this.GE = GE;
                        this.GI = Gi;
                        this.no = no;
                }

                public int compareTo(Student o) {
                        return (o.GE + o.GI) - (GE + GI);
                }
        }

        private static class School {
                int shouldexceed;
                int hasexceed = 0;
                int AllStudent[];

                public School(int shouldexceed) {
                        this.shouldexceed = shouldexceed;
                        AllStudent = new int[shouldexceed + 5];
                }
        }

        private static int N, M, K;
        private static Student student[];
        private static School school[];

        public static void main(String args[]) {
                while (in.hasNext()) {
                        N = in.nextInt();
                        student = new Student[N];
                        M = in.nextInt();
                        school = new School[M];
                        K = in.nextInt();
                        for (int i = 0; i < M; i++) {
                                school[i] = new School(in.nextInt());
                        }
                        for (int i = 0; i < N; i++) {
                                student[i] = new Student(in.nextInt(), in.nextInt(), i);
                                student[i].AllChoice = new int[K];
                                for (int ii = 0; ii < K; ii++) {
                                        student[i].AllChoice[ii] = in.nextInt();
                                }
                        }// 输入完毕
                        result();
                }
        }

        private static void result() {
                Arrays.sort(student);
                student[0].rank = 0;
                for (int i = 1; i < N; i++) {
                        if ((student[i].GE != student[i - 1].GE)
                                        || (student[i].GI != student[i - 1].GI)) {
                                student[i].rank = i;
                        } else {
                                student[i].rank = student[i - 1].rank;
                        }
                }// 求每个学生的排名0~N-1
                for (int i = 0; i < N; i++) {// 对每个学生进行处理
                        for (int ii = 0; ii < K; ii++) {// 对一个学生的所有选择进行处理
                                if (school[student[i].AllChoice[ii]].hasexceed < school[student[i].AllChoice[ii]].shouldexceed) {
                                        school[student[i].AllChoice[ii]].AllStudent[school[student[i].AllChoice[ii]].hasexceed] = student[i].no;
                                        school[student[i].AllChoice[ii]].hasexceed++;
                                        student[i].TheSchool = student[i].AllChoice[ii];
                                        break;
                                }
                                if ((student[i].rank == student[i - 1].rank)
                                                && (student[i - 1].TheSchool == student[i].AllChoice[ii])) {// 特殊情况
                                        school[student[i].AllChoice[ii]].AllStudent[school[student[i].AllChoice[ii]].hasexceed] = student[i].no;
                                        school[student[i].AllChoice[ii]].hasexceed++;
                                        student[i].TheSchool = student[i].AllChoice[ii];
                                        break;
                                }
                        }
                }// 所有学生处理完毕,接下来输出school信息
                for (int i = 0; i < M; i++) {
                        if (school[i].hasexceed > 1) {
                                Arrays.sort(school[i].AllStudent, 0, school[i].hasexceed);
                                System.out.print(school[i].AllStudent[0]);
                                for (int ii = 1; ii < school[i].hasexceed - 1; ii++) {
                                	System.out.print(" " + school[i].AllStudent[ii]);
                                }
                                System.out.println(" " + school[i].AllStudent[school[i].hasexceed - 1]);
                        } else if (school[i].hasexceed == 1) {
                        	System.out.println(school[i].AllStudent[0]);
                        } else {
                        	System.out.println();
                        }
                }
        }
}


4,备注


上述代码直接复制是AC不了的,把类名problem_1005改为Main就可以直接上传通过了:)

如果读者有更好的想法,希望大家相互交流,共同提高

分享到:
评论

相关推荐

Magicbox
Global site tag (gtag.js) - Google Analytics