PAT-1080 Graduate Admission

本文介绍了一个自动化的研究生招生系统的设计方案。该系统基于申请者的全国入学考试成绩和面试成绩进行综合评分,并根据评分高低及学校名额自动录取申请者。文章详细阐述了系统的录取规则和流程,并提供了完整的代码实现。

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

1080 Graduate Admission (30)(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

 根据成绩排序,从高分开始录取,注意相同排名的学生可以超额录取。学校录取最低分可以判断是否需要超额录取。之前有一个测试点一直超时,以为是STL容器搞多了,尝试了多种写法,其实不是,STL对时间的消耗很少,嵌套for循环(即使感觉每个循环只循环几次)的影响要大几个数量级,以后优化时间要从减少循环下手。

#include<stdio.h>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;

typedef struct stu{
	int id,ge,gi;
	int ch[5];
}stu;
int n,m,K;
int quota[105];
int lowestge[105];
int lowestgi[105];
priority_queue<int,vector<int>,greater<int> > result[105];//录取结果
vector<stu> s;

bool cmp(stu s1,stu s2){
	if((s1.ge+s1.gi)!=(s2.ge+s2.gi))
		return (s1.ge+s1.gi)>(s2.ge+s2.gi);
	else{
		if(s1.ge!=s2.ge)
			return s1.ge>s2.ge;
		else return false;
	}
}
int main(){
	scanf("%d %d %d",&n,&m,&K);
	for(int i=0;i<m;i++)
		scanf("%d",quota+i);
	
	for(int i=0;i<n;i++){
		stu st;st.id=i;
		scanf("%d %d",&st.ge,&st.gi);
		for(int k=0;k<K;k++){
			scanf("%d",&st.ch[k]);
		}
		s.push_back(st);
	}
	sort(s.begin(),s.end(),cmp);
	fill(lowestge,lowestge+m,-1);
	fill(lowestgi,lowestgi+m,-1);

	for(int i=0;i<s.size();i++){
		for(int j=0;j<K;j++){
			int sch=s[i].ch[j];
			if(quota[sch]>0||
				(lowestgi[sch]==s[i].gi&&lowestge[sch]==s[i].ge)){
					result[sch].push(s[i].id);		
					lowestgi[sch]=s[i].gi;
					lowestge[sch]=s[i].ge;
					quota[sch]--;
					break;
			}
		}
	}

	for(int i=0;i<m;i++){
		if(result[i].size()==0){
			printf("\n");
			continue;
		}
		printf("%d",result[i].top());result[i].pop();
		for(;!result[i].empty();result[i].pop())
			printf(" %d",result[i].top());

		printf("\n");
	}

	return 0;
}

 

<think>好的,我需要帮助用户理解`--enable-admission-plugins`参数,特别是它后面列出的那些插件。首先,用户之前问过`--enable-swagger-ui=true`,现在转向Kubernetes相关的参数,可能是在学习或配置K8s集群。 首先,确认这个参数的作用。`--enable-admission-plugins`用于启用Kubernetes API服务器的准入控制插件。每个插件都有不同的功能,比如NamespaceLifecycle管理命名空间生命周期,NodeRestriction限制节点权限等。 接下来,要逐一解释用户列出的每个插件:NamespaceLifecycle、NodeRestriction、LimitRanger、ServiceAccount、DefaultStorageClass、ResourceQuota。需要简明扼要地说明每个插件的作用,比如LimitRanger设置资源限制,ResourceQuota管理资源配额等。 然后,考虑用户可能的深层需求。用户可能是集群管理员,需要配置安全的准入控制,或者是开发者在部署应用时遇到问题。因此,除了基本功能介绍,还需要提供典型使用场景,例如多租户集群、资源管理、安全加固等。 配置方式部分,需要说明如何修改kube-apiserver的配置文件,添加这个参数并启用插件。可能用户需要具体的示例,比如在/etc/kubernetes/manifests/kube-apiserver.yaml中添加对应的命令行参数。 注意事项方面,要提醒用户生产环境中谨慎选择插件,避免启用过多影响性能,同时注意插件顺序可能影响行为。此外,某些插件需要额外配置,如ResourceQuota需要定义ResourceQuota对象。 最后,验证部分要告诉用户如何检查插件是否生效,比如检查kube-apiserver日志或描述命名空间查看配额。常见问题排查点可能包括配置错误、依赖缺失或冲突插件。 需要确保回答结构清晰,分点列出,使用用户容易理解的语言,避免过多技术术语,同时保持准确。可能用户需要快速参考,因此对比表格或示例配置会有帮助。同时,参考之前的回答格式,保持一致性,比如参数作用、适用场景、配置方式、注意事项等部分。</think>### 关于 `--enable-admission-plugins=NamespaceLifecycle,NodeRestriction,LimitRanger,ServiceAccount,DefaultStorageClass,ResourceQuota` 参数的介绍及使用场景: --- ### 1. **参数作用** `--enable-admission-plugins` 是 Kubernetes API 服务器的配置参数,用于启用特定的 **准入控制插件(Admission Plugins)**。这些插件在 API 请求处理过程中对资源操作(如创建、更新、删除)进行拦截和验证,用于增强集群的安全性、资源管理和策略执行。 --- ### 2. **列出的准入插件功能** | 插件名称 | 核心功能 | |------------------------|--------------------------------------------------------------------------| | **NamespaceLifecycle** | 管理命名空间生命周期(如禁止删除`active`命名空间,自动清理已删除的命名空间) | | **NodeRestriction** | 限制 kubelet 的权限(如只能修改自身节点相关资源) | | **LimitRanger** | 为命名空间设置默认资源限制(CPU/内存)或自动注入资源配额 | | **ServiceAccount** | 自动为 Pod 注入 ServiceAccount 凭据(若未显式指定) | | **DefaultStorageClass**| 为未指定存储类的 PersistentVolumeClaim 自动分配默认存储类 | | **ResourceQuota** | 监控并限制命名空间的资源使用总量(如 Pod 数量、CPU/内存配额等) | --- ### 3. **适用场景** #### 场景 1:**多租户集群管理** - 通过 `NamespaceLifecycle` 和 `ResourceQuota` 实现租户资源隔离和配额控制。 - 使用 `LimitRanger` 防止单个应用过度占用资源。 #### 场景 2:**安全加固** - `NodeRestriction` 防止恶意节点篡改其他节点或集群资源。 - `ServiceAccount` 确保 Pod 权限最小化。 #### 场景 3:**存储自动化** - `DefaultStorageClass` 简化存储声明流程,避免用户遗漏存储类配置。 --- ### 4. **配置方式** #### 修改 `kube-apiserver` 配置文件(通常位于 `/etc/kubernetes/manifests/kube-apiserver.yaml`): ```yaml apiVersion: v1 kind: Pod metadata: name: kube-apiserver spec: containers: - command: - kube-apiserver - --enable-admission-plugins=NamespaceLifecycle,NodeRestriction,LimitRanger,ServiceAccount,DefaultStorageClass,ResourceQuota # 其他参数... ``` --- ### 5. **注意事项** - **生产环境推荐配置**: 这些插件是 Kubernetes 官方推荐的最小安全准入控制集合(参考 [CIS Kubernetes 基准](https://www.cisecurity.org/benchmark/kubernetes/))。 - **性能影响**: 启用过多插件可能增加 API 请求延迟,需根据实际需求选择。 - **依赖顺序**: 插件执行顺序可能影响行为(例如 `ResourceQuota` 需在 `LimitRanger` 之后执行)。 - **动态更新**: Kubernetes 1.26+ 支持通过 `--admission-control-config-file` 动态加载插件配置。 --- ### 6. **验证是否生效** - 检查 API 服务器日志: ```bash journalctl -u kube-apiserver | grep "admission plugin" ``` - 查看命名空间资源配额: ```bash kubectl describe namespace default ``` --- ### 7. **常见问题排查** | 问题现象 | 可能原因 | 解决方案 | |-------------------------------|------------------------------|-----------------------------------| | Pod 创建失败,提示资源不足 | `ResourceQuota` 限制了配额 | 调整命名空间的 ResourceQuota 配置 | | 存储声明未自动分配存储类 | `DefaultStorageClass` 未启用 | 检查集群是否设置了默认存储类 | | 节点无法修改自身 Pod | `NodeRestriction` 权限过严 | 检查 kubelet 证书的 CN 配置 | --- ### 附:其他常用准入插件补充 - **PodSecurity**(替代 PSP):实施 Pod 安全策略(如禁止特权容器)。 - **MutatingAdmissionWebhook**:动态修改 API 请求(如自动注入 Sidecar)。 - **ValidatingAdmissionWebhook**:自定义校验规则(如验证镜像签名)。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值