测试点1,2过不去,有没有懂哥知道为什么的嘛?
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int n,m,k;
struct node{
int same;
int id;
int rank;
int grade1;
int grade2;
vector<int> choices;
};
struct school{//已录取的人数和被录取的学生的学号;
int num=0;
vector<int >student;//结构体内的vector要在结构体外分配大小;
};
bool cmp(node a,node b){
if((a.grade1+a.grade2)/2!=(b.grade1+b.grade2)/2){
return (a.grade1+a.grade2)/2>(b.grade1+b.grade2)/2;
}else {
return a.grade1>b.grade1;
}
}
int main(){
scanf("%d %d %d",&n,&m,&k);
vector<int>admisson(m);
vector<node> v(n);
for(int i=0;i<n;i++){
v[i].choices.resize(k,0);
}
vector<school >school(m);
for(int i=0;i<m;i++){
scanf("%d",&admisson[i]);
}
for(int i=0;i<n;i++){
scanf("%d %d",&v[i].grade1,&v[i].grade2);
v[i].id=i;
for(int j=0;j<k;j++){
scanf("%d",&v[i].choices[j]);
}
}
sort(v.begin(),v.end(),cmp);
for(int i=0;i<n;i++){
v[i].rank=i+1;
if(i!=0&&v[i].grade1==v[i-1].grade1&&(v[i].grade1+v[i].grade2)/2==(v[i-1].grade1+v[i-1].grade2)/2){
v[i].rank=v[i-1].rank;
}
}
for(int i=0;i<n;i++){
for(int j=0;j<k;j++){
if(school[v[i].choices[j]].num!=admisson[v[i].choices[j]]){
school[v[i].choices[j]].student.push_back(v[i].id);
school[v[i].choices[j]].num++;
break;
}else {
int num1=school[v[i].choices[j]].student.back();
if(v[i].rank==v[num1].rank){
school[v[i].choices[j]].student.push_back(v[i].id);
break;
}
}
}
}
for(int i=0;i<m;i++){
sort(school[i].student.begin(),school[i].student.end());
if(school[i].num!=0){
for(int j=0;j<school[i].student.size();j++){
if(j!=0)printf(" ");
printf("%d",school[i].student[j]);
}
printf("\n");
}else printf("\n");
}
return 0;
}