主要是模拟,创建两个结构体保存学生、学校数据。理清思路就好了
这次的bug在于 cmp函数中,if 以后必须出现else而不是else if,否则会导致没有return
还有如果数组过于复杂,将其赋值给一个临时变量,便于理解和书写,比如代码中的 prefer = stu[i].choice[j]
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
struct student{
int ge;
int gi;
int fg;
int choice[6];
int range;
int mark;
}stu[40010];
struct school{
int quota;
int number=0;
int mark[40010];
}sch[105];
bool cmp(student a,student b){
if (a.fg!=b.fg) return a.fg>b.fg;
else return a.ge>b.ge;
//这里不要写else if (a.ge!=b.ge) 会导致没有return 运行超时, 以及一个测试点不过
}
bool cmp1(int a, int b){
return a<b;
}
int main(){
int n,m,k;
scanf("%d %d %d",&n,&m,&k);
for (int i=0;i<m;i++){
scanf("%d",&sch[i].quota);
}
for (int i=0;i<n;i++){
scanf("%d %d",&stu[i].ge,&stu[