pat-1080. Graduate Admission (30)

本文介绍了一个用于自动处理研究生招生流程的程序设计案例。该程序能够根据考生的国家考试成绩和面试成绩,结合考生的学校志愿及学校的招生名额,自动完成录取工作。特别地,程序考虑了同分情况下的特殊处理规则。

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


1080. Graduate Admission (30)

时间限制
200 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue

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 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.

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 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.

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

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;






class node2{
public:int ge,gi;
  vector<int> v;
  int temp;
  int num;
 
};


node2 *arr;


bool cmp(node2 a,node2 b){
if(a.ge+a.gi>b.ge+b.gi) return true;
if(a.ge+a.gi<b.ge+b.gi) return false;
else{
if(a.ge>b.ge) return true;
else return false;
}


}


int main(){


int n,m,k;
cin>>n>>m>>k;
arr=new node2[n];



int size[100];
vector<int> school[100];
int last[100];
for(int i=0;i<m;i++)
{
cin>>size[i];
last[i]=-1;
}
for(int i=0;i<n;i++)
{int t;
cin>>arr[i].ge>>arr[i].gi;
arr[i].temp=1;arr[i].num=i;
for(int j=0;j<k;j++)
{
cin>>t;
arr[i].v.push_back(t);

}


}
sort(arr,arr+n,cmp);
for(int i=0;i<n;i++)
{
int t;
for(int j=0;j<k;j++)
{
t=arr[i].v[j];
if(size[t]>0) {
arr[i].temp=0,last[t]=i,size[t]--;
school[t].push_back(arr[i].num);
break;
}
else{
int tt=last[t];
if(arr[tt].ge==arr[i].ge&&arr[tt].gi==arr[i].gi)
{arr[i].temp=0,last[t]=i,size[t]--;
school[t].push_back(arr[i].num);
break;
}
}
}
}
for(int i=0;i<m;i++)
{
sort(school[i].begin(),school[i].end(),less<int>());
for(int j=0;j<school[i].size();j++)
{if(j==0) cout<<school[i][j];
else cout<<" "<<school[i][j];
}
cout<<endl;
}
return 0;
}

<think>好的,我现在遇到了一个kubectl的问题,需要仔细分析一下。用户运行了`kubectl create -f custom-resources.yaml`,然后报错说验证custom-resources.yaml时出错。首先,我应该考虑可能的原因,然后一步步帮助用户排查。 首先想到的是YAML语法错误。用户可能不小心在缩进时用了空格和Tab混用,或者结构不正确。这时候需要检查文件是否有语法错误。可以用在线YAML校验工具或者`yamllint`来检查。另外,是否缺少了必要的字段?比如apiVersion、kind、metadata这些必须的字段,如果有遗漏,kubectl会报错。 其次是资源定义是否符合Kubernetes的API规范。可能用户使用的apiVersion不对,或者资源类型不存在。比如,如果是自定义资源(CRD),需要先确认是否已经创建了对应的CustomResourceDefinition。如果CRD还没被创建,直接创建资源实例就会失败。这时候应该提醒用户检查CRD是否存在,用`kubectl get crd`查看。 接下来是版本兼容性问题。用户可能使用的Kubernetes集群版本不支持资源中指定的apiVersion。比如,某个资源在v1版本才有,而集群还在v1beta1。这时候需要确认集群版本和资源定义的兼容性,可以用`kubectl version`查看版本信息。 然后,字段名称或值是否正确?比如,是否有拼写错误,像metdata而不是metadata,或者类型不匹配,比如字符串应该用引号却没用。这时候需要用户仔细检查每个字段,特别是复制粘贴时容易出错的地方。 另外,验证失败还可能因为启用了准入控制插件,比如某些Webhook拒绝了资源的创建。这时候可以尝试加上`--validate=skip`跳过验证,但要注意这可能掩盖其他问题。不过生产环境慎用,可能不安全。 其他可能性包括kubectl版本和集群版本不匹配,或者配置文件中的上下文不正确,导致连接到错误的集群。用户需要确认kubectl配置是否正确,使用`kubectl config current-context`检查当前上下文,或者切换上下文到正确的集群。 总结排查步骤的话,应该建议用户先检查YAML语法,再确认CRD是否存在,然后核对apiVersion和字段是否正确,接着考虑集群版本和准入控制的影响。提供具体的命令和示例能帮助用户更快定位问题。比如,给出如何用`kubectl get crd`检查CRD,或者用`--validate=skip`的示例命令。 可能需要提醒用户注意常见的错误点,比如缩进问题、字段拼写错误,以及确保CRD已正确应用。另外,如果用户是新手,可能需要解释一些术语,比如CRD是什么,为什么需要先创建它,这样他们能更好地理解问题所在。 最后,如果用户还是无法解决,建议他们提供具体的YAML内容(注意脱敏),或者错误信息的完整输出,以便更精准地诊断问题。不过要确保他们不分享敏感信息。</think>你遇到的错误`error validating "custom-resources.yaml"`表明Kubernetes在尝试创建资源时未能通过验证。以下是逐步排查和解决问题的指南: --- ### **1. 检查YAML语法** **可能原因**:YAML文件存在语法错误(如缩进错误、冒号缺失、引号不匹配等)。 **解决方法**: - 使用工具验证YAML语法: ```bash yamllint custom-resources.yaml # 需要安装yamllint ``` - 检查是否缺少必需字段(如`apiVersion`, `kind`, `metadata.name`)。 --- ### **2. 确认资源类型是否存在** **可能原因**:尝试创建的资源(如自定义资源CRD)未预先定义。 **解决方法**: - 如果是自定义资源(CustomResource),需先创建对应的CRD: ```bash kubectl apply -f custom-resource-definition.yaml ``` - 检查CRD是否已存在: ```bash kubectl get crd # 查看自定义资源定义列表 ``` --- ### **3. 验证API版本兼容性** **可能原因**:`apiVersion`字段值与集群版本不兼容。 **解决方法**: - 检查集群支持的API版本: ```bash kubectl api-versions # 列出所有支持的API版本 ``` - 将YAML中的`apiVersion`调整为集群支持的版本。 --- ### **4. 检查字段名称和值** **可能原因**:字段名称拼写错误或值类型不合法(如数字写成字符串)。 **解决方法**: - 对照Kubernetes官方文档或CRD的Schema定义,检查字段名称和值类型。 - 示例错误:`metdata`(正确应为`metadata`)或`replicas: "3"`(应为`replicas: 3`)。 --- ### **5. 绕过验证(谨慎使用)** **可能原因**:验证逻辑本身存在问题(如Webhook故障)。 **解决方法**: - 跳过验证(仅用于调试): ```bash kubectl create -f custom-resources.yaml --validate=skip ``` - **注意**:生产环境慎用,可能引发安全问题。 --- ### **6. 检查准入控制器(Admission Controllers)** **可能原因**:准入控制器(如ValidatingWebhook)拒绝了资源创建。 **解决方法**: - 查看准入控制器的日志: ```bash kubectl logs -n <namespace> <webhook-pod-name> ``` - 临时禁用Webhook(如有权限)进行测试。 --- ### **7. 确认集群上下文** **可能原因**:kubectl连接的集群不正确(如指向测试环境而非生产环境)。 **解决方法**: - 检查当前上下文: ```bash kubectl config current-context ``` - 切换上下文: ```bash kubectl config use-context <目标上下文名称> ``` --- ### **示例调试流程** ```bash # 1. 检查YAML语法 yamllint custom-resources.yaml # 2. 检查CRD是否存在 kubectl get crd | grep <资源类型> # 3. 尝试创建资源(显示详细错误) kubectl create -f custom-resources.yaml --v=9 # 4. 检查API版本兼容性 kubectl api-resources | grep <资源类型> ``` --- ### **常见问题总结** | 问题类型 | 典型表现 | 解决命令 | |--------------------|-----------------------------|----------------------------------| | CRD未定义 | `no matches for kind` | `kubectl apply -f crd.yaml` | | 字段拼写错误 | `unknown field` | 对照文档修正字段名 | | 类型不匹配 | `invalid type` | 修正值为整数/布尔值/字符串 | | API版本过时 | `no registered resource` | `kubectl api-versions` + 调整YAML | 如果问题仍未解决,请提供以下信息: 1. `custom-resources.yaml` 内容(脱敏后)。 2. 完整的错误输出。 3. 集群版本(`kubectl version`)。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值