演算法練習-題目1005:Graduate Admission

來源:互聯網
上載者:User

串連: http://ac.jobdu.com/problem.php?pid=1005

題目描述:

    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 32 1 2 2 2 3100 100 0 1 260 60 2 3 5100 90 0 3 490 100 1 2 090 90 5 1 380 90 1 0 280 80 0 1 280 80 0 1 280 70 1 3 270 80 1 2 3100 100 0 2 4
範例輸出:
0 1035 6 72 81 4

package util;import java.io.BufferedInputStream;import java.util.ArrayList;import java.util.Arrays;import java.util.Scanner;public class Main {static Student students[] = null;static School schools[] = null;static int limits[] = null;public static void main(String[] args) {int strNum,schNum,choices;Scanner s = new Scanner(new BufferedInputStream(System.in));while(s.hasNextInt()){strNum = s.nextInt();schNum = s.nextInt();choices = s.nextInt();students = new Student[strNum];schools = new School[schNum];for(int i=0; i<schools.length; i++)schools[i] = new School();limits = new int[schNum];for(int i=0; i<schNum; i++)limits[i] = s.nextInt();for(int i=0; i<strNum; i++){students[i] = new Student();students[i].score1 = s.nextInt();students[i].score2 = s.nextInt();students[i].index = i;students[i].perfers = new int[choices];for(int j=0; j<choices; j++)students[i].perfers[j] = s.nextInt();}Arrays.sort(students);for(int i=0; i<students.length; i++){for(int j=0; j<choices; j++){ArrayList<Student> list = schools[students[i].perfers[j]].students;if(list.size() < limits[students[i].perfers[j]]){list.add(students[i]);//System.out.println("學校:" + students[i].perfers[j] + "學生:" + students[i].index +"  " +list.size());break;}else if(list.size() >= limits[students[i].perfers[j]]){if(students[i].compareTo(list.get(list.size()-1)) == 0 ){list.add(students[i]);break;}}}}for(int i=0; i<schools.length; i++){int arr[] = new int[schools[i].students.size()];for(int j=0; j<schools[i].students.size(); j++){arr[j] = schools[i].students.get(j).index;}Arrays.sort(arr);for(int j=0; j<arr.length; j++){if(j != arr.length-1)System.out.print( arr[j] + " ");elseSystem.out.print(arr[j]);}System.out.println();}}}}class School{ArrayList<Student> students = new ArrayList<Student>();}class Student implements Comparable<Student>{public int index;int score1;int score2;int perfers[];public int compareTo(Student o) {double s1 = ((this.score1 + this.score2)/2.0);double s2 =  ((o.score1 + o.score2)/2.0);if(s1 == s2){return o.score1 -this.score1;}else if(s1 > s2){return -1;}elsereturn 1;}}


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.