算法练习-题目1005:Graduate Admission

本文介绍了一个自动化的招生系统设计,该系统能够处理大量的入学申请,并根据申请者的成绩和学校名额进行自动化的录取流程。系统考虑了申请者的国家考试成绩、面试成绩及首选学校等综合因素。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

连接: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 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


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] + " ");
					else
						System.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;
		}else
			return 1;
			
		
	}
}



kubernetes GitLab + Ingressroot@k8s-m001:~/devops/test-devops/gitlab# ll total 44 drwxr-xr-x 3 root root 4096 Jun 15 18:25 ./ drwxr-xr-x 7 root root 4096 Jun 15 18:21 ../ -rw-r--r-- 1 root root 1337 Jun 15 18:21 gitlab-deployment.yaml -rw-r--r-- 1 root root 520 Jun 15 18:22 gitlab-ingress.yaml -rw-r--r-- 1 root root 723 Jun 15 17:51 gitlab-nfs-pvc-pro.yaml -rw-r--r-- 1 root root 58 Jun 14 21:55 gitlab-ns.yaml -rw-r--r-- 1 root root 293 Jun 15 18:25 gitlab-services.yaml drwxrwxrwx 2 root root 4096 Jun 15 16:31 gitlab.wh02.com_nginx/ -rw-r--r-- 1 root root 9078 Jun 15 16:28 gitlab.wh02.com_nginx.zip root@k8s-m001:~/devops/test-devops/gitlab# cat gitlab-deployment.yaml apiVersion: apps/v1 kind: Deployment metadata: name: gitlab namespace: gitlab spec: selector: matchLabels: app: gitlab replicas: 1 template: metadata: labels: app: gitlab spec: securityContext: fsGroup: 1000 containers: - name: gitlab image: harbor.wh02.com/cicd/gitlab/gitlab-ce:17.11.0-ce.0 imagePullPolicy: Always ports: - containerPort: 80 - containerPort: 22 env: - name: GITLAB_OMNIBUS_CONFIG value: | external_url 'https://gitlab.wh02.com' gitlab_rails['initial_root_password'] = "Aa123123" gitlab_rails['gitlab_default_locale'] = 'zh_CN' gitlab_rails['gitlab_default_locale_in_system'] = true volumeMounts: - name: gitlab-storage mountPath: /var/opt/gitlab subPath: data - name: gitlab-storage mountPath: /var/log/gitlab subPath: logs - name: gitlab-storage mountPath: /etc/gitlab subPath: config resources: requests: cpu: "2" memory: "5Gi" limits: cpu: "2" memory: "6Gi" volumes: - name: gitlab-storage persistentVolumeClaim: claimName: gitlab-pvc root@k8s-m001:~/devops/test-devops/gitlab# cat gitlab-ingress.yaml apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: gitlab-ingress namespace: gitlab annotations: nginx.ingress.kubernetes.io/ssl-redirect: "true" spec: ingressClassName: nginx tls: - hosts: - gitlab.wh02.com secretName: gitlab-tls rules: - host: gitlab.wh02.com http: paths: - path: / pathType: Prefix backend: service: name: gitlab-service port: number: 80 root@k8s-m001:~/devops/test-devops/gitlab# cat gitlab-nfs-pvc-pro.yaml apiVersion: storage.k8s.io/v1 kind: StorageClass metadata: name: nfs-gitlab-static provisioner: kubernetes.io/no-provisioner volumeBindingMode: WaitForFirstConsumer reclaimPolicy: Retain --- apiVersion: v1 kind: PersistentVolume metadata: name: gitlab-pv spec: capacity: storage: 50Gi accessModes: - ReadWriteMany nfs: server: 192.168.3.101 path: /data/k8sdata/gitlab_data storageClassName: nfs-gitlab-static persistentVolumeReclaimPolicy: Retain --- apiVersion: v1 kind: PersistentVolumeClaim metadata: name: gitlab-pvc namespace: gitlab spec: accessModes: - ReadWriteMany resources: requests: storage: 50Gi storageClassName: nfs-gitlab-static volumeName: gitlab-pv root@k8s-m001:~/devops/test-devops/gitlab# cat gitlab-ns.yaml apiVersion: v1 kind: Namespace metadata: name: gitlab root@k8s-m001:~/devops/test-devops/gitlab# cat gitlab-services.yaml apiVersion: v1 kind: Service metadata: name: gitlab-service namespace: gitlab spec: selector: app: gitlab type: NodePort ports: - name: http port: 80 targetPort: 80 # nodePort: 30030 - name: ssh port: 22 targetPort: 22 # nodePort: 30022 root@k8s-m001:~/devops/test-devops/gitlab# kubectl get secrets -n gitlab No resources found in gitlab namespace. root@k8s-m001:~/devops/test-devops/gitlab# kubectl get secrets -A NAMESPACE NAME TYPE DATA AGE ingress-nginx ingress-nginx-admission Opaque 3 97m jenkins harbor-pull-secret kubernetes.io/dockerconfigjson 1 7h41m kube-system calico-etcd-secrets Opaque 3 40h kubernetes-dashboard dashboard-admin-user kubernetes.io/service-account-token 3 65d kubernetes-dashboard kubernetes-dashboard-certs Opaque 0 65d kubernetes-dashboard kubernetes-dashboard-csrf Opaque 1 65d kubernetes-dashboard kubernetes-dashboard-key-holder Opaque 2 65d kuboard kuboard-admin-token kubernetes.io/service-account-token 3 40h kuboard kuboard-viewer-token kubernetes.io/service-account-token 3 40h root@k8s-m001:~/devops/test-devops/gitlab# kubectl get pv,pvc -n gitlab NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS VOLUMEATTRIBUTESCLASS REASON AGE persistentvolume/gitlab-pv 50Gi RWX Retain Bound gitlab/gitlab-pvc nfs-gitlab-static <unset> 44m persistentvolume/jenkins-pv 10Gi RWX Retain Released jenkins/jenkins-pvc <unset> 26h persistentvolume/pvc-1464be8d-5bc8-4ba1-8d91-c282167ea4cf 50Gi RWX Delete Bound jenkins/jenkins-pvc nfs-dynamic <unset> 7h41m persistentvolume/pvc-49a9790f-7ebf-43a6-8454-b90cf50d2f3d 50Gi RWX Retain Released jenkins/jenkins-pvc nfs-dynamic <unset> 7h54m persistentvolume/pvc-4ddd9d5b-a734-4889-af64-0c96f340ce11 50Gi RWX Retain Released jenkins/jenkins-pvc nfs-dynamic <unset> 8h NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS VOLUMEATTRIBUTESCLASS AGE persistentvolumeclaim/gitlab-pvc Bound gitlab-pv 50Gi RWX nfs-gitlab-static <unset> 44m
06-17
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值