1080. Graduate Admission (30)<28分>

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


这题,真受罪。我没办法的都给改成递归了,还是最后一个点过不去

主要就是同样的排名,然后分学校,这个点不好弄

例如输出的第三行5 6 7 即使学校满了,我和你排名一样,仍然入学


我第一次提交28分,最后一个点过不去,把别人AC的代码弄过来

测试了一组数据

5 2 2
1 1
10 10 0 1
10 10 0 1
10 10 1 0
10 10 1 0
10 10 0 1

对应输出为:
0 1 4
2 3



我的代码输出为

0 1

2 3 4


感觉自己可能理解错了

然后改成递归,输出和AC的代码一样。还是错误,还是不晓得最后一个点是啥


第一次提交:

#include<cstdio>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<queue>
#include<vector>
#include<map>
using namespace std;
typedef struct node{
	int ge,gi;
	double avg;
	int a[100];
	int name;
}node;
bool cmp(node n1,node n2){
	if(n1.avg==n2.avg){
		return n1.ge>n2.ge;
	}
	return n1.avg>n2.avg;
}
int main(){
	int n,m,k;
	cin>>n>>m>>k;
	static node no[40001];
	int peo[1001];
	int len[1001]={0};
	for(int i=0;i<m;i++){
		scanf("%d",&peo[i]);
	}
	for(int i=0;i<n;i++){
		int ge,gi;
		scanf("%d%d",&ge,&gi);
		no[i].ge=ge;
		no[i].gi=gi;
		no[i].avg=(ge+gi)/2.0;
		no[i].name=i;
		for(int j=0;j<k;j++){
			int num;
			scanf("%d",&num);
			no[i].a[j]=num;
		}
	}
	sort(no,no+n,cmp);
	/*for(int i=0;i<n;i++){
		printf("%d %.1f %d %d",no[i].name,no[i].avg,no[i].ge,no[i].gi);
		for(int j=0;j<k;j++) cout<<" "<<no[i].a[j];
		cout<<endl;
	}*/
	static int fz[40001][200];
	int geshu[2000]={0};
	for(int i=0;i<n;i++){
		for(int j=0;j<k;j++){
			if(len[no[i].a[j]]<peo[no[i].a[j]]){
			   len[no[i].a[j]]++;
			   fz[no[i].a[j]][geshu[no[i].a[j]]++]=no[i].name;
			   int flag=0;
			   
			   int school=no[i].a[j];
			   double avg=no[i].avg;
			   int g=no[i].ge;
			   while(flag!=1){
			   	 if(no[i+1].avg==avg&&no[i+1].ge==g){
			   	 	
			   	 	for(int l=0;l<k;l++){
			   	 		 if(no[i+1].a[l]==school){
			   	 		 	len[no[i+1].a[l]]++;
			   	 		 	fz[no[i+1].a[l]][geshu[no[i+1].a[l]]++]=no[i+1].name;
						    i++;
						    break;
						 }
						 else{
						 	if(len[no[i+1].a[l]]>=peo[no[i+1].a[l]])
						 	continue;
						 	else{
						 		flag=1;
						 		break;
							 }
						 }
					}
					
				 }
				 else flag=1;
			   }
			   break;	
			}
		}
	}
	for(int i=0;i<m;i++){
		int a[40001];
		for(int j=0;j<geshu[i];j++){
			a[j]=fz[i][j];
		}
		if(geshu[i]==0)
		cout<<endl;
		else{
			sort(a,a+geshu[i]);
			printf("%d",a[0]);
			for(int j=1;j<geshu[i];j++){
				printf(" %d",a[j]);
			}
			cout<<endl;
		}
	}
	return 0;
}


改为递归后提交:

#include<cstdio>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<queue>
#include<vector>
#include<map>
using namespace std;
int n,m,k;

int peo[40001];
int len[40001]={0};
static int fz[1001][40001+10];
int geshu[40001+10]={0};
typedef struct node{
	int ge,gi;
	double avg;
	int a[200];
	int name;
}node;
static node no[40000+10];
bool cmp(node n1,node n2){
	if(n1.avg==n2.avg){
		return n1.ge>n2.ge;
	}
	return n1.avg>n2.avg;
}
void f(int &i,int school){
double avg=no[i].avg;
int g=no[i].ge;
if(i>=n) return;
if(no[i+1].avg==avg&&no[i+1].ge==g){
			   	 	
	for(int l=0;l<k;l++){
		if(no[i+1].a[l]==school||len[no[i+1].a[l]]<peo[no[i+1].a[l]]){
			len[no[i+1].a[l]]++;
			fz[no[i+1].a[l]][geshu[no[i+1].a[l]]++]=no[i+1].name;
			i++;
			f(i,no[i+1].a[l]);
			break;
     	}
	}
					
 }
else return;
}
int main(){
	
	cin>>n>>m>>k;
	
	for(int i=0;i<m;i++){
		scanf("%d",&peo[i]);
	}
	for(int i=0;i<n;i++){
		int ge,gi;
		scanf("%d%d",&ge,&gi);
		no[i].ge=ge;
		no[i].gi=gi;
		no[i].avg=(ge+gi)/2.0;
		no[i].name=i;
		for(int j=0;j<k;j++){
			int num;
			scanf("%d",&num);
			no[i].a[j]=num;
		}
	}
	sort(no,no+n,cmp);
	/*for(int i=0;i<n;i++){
		printf("%d %.1f %d %d",no[i].name,no[i].avg,no[i].ge,no[i].gi);
		for(int j=0;j<k;j++) cout<<" "<<no[i].a[j];
		cout<<endl;
	}*/
	
	for(int i=0;i<n;i++){
		for(int j=0;j<k;j++){
			if(len[no[i].a[j]]<peo[no[i].a[j]]){
			   len[no[i].a[j]]++;
			   fz[no[i].a[j]][geshu[no[i].a[j]]++]=no[i].name;
			   f(i,no[i+1].a[j]);
			   break;	
			}
		}
	}
	for(int i=0;i<m;i++){
		int a[40001];
		for(int j=0;j<geshu[i];j++){
			a[j]=fz[i][j];
		}
		if(geshu[i]==0)
		cout<<endl;
		else{
			sort(a,a+geshu[i]);
			printf("%d",a[0]);
			for(int j=1;j<geshu[i];j++){
				printf(" %d",a[j]);
			}
			cout<<endl;
		}
	}
	return 0;
}
另附AC代码:

#include <algorithm>
#include <cstdio>
#include <vector>
using namespace std;
int n, m, k;
struct stu {
    int id;
    int GE, GI, Grade, rank;
    vector<int> vSchool;
};

struct sch {
    int nowNum;
    int maxNum;
    vector<int> stuID;
    int lastRank;
};

bool cmp1(stu a, stu b) {
    if(a.Grade != b.Grade) {
        return a.Grade > b.Grade;
    } else {
        return a.GE > b.GE;
    }
    
}

int main() {
    scanf("%d%d%d", &n, &m, &k);
    vector<stu> student(n);
    vector<sch> school(m);
    for(int i = 0; i < m; i++) {
        int temp;
        scanf("%d", &temp);
        school[i].maxNum = temp;
        school[i].nowNum = 0;
        school[i].lastRank = -1;
    }
    for(int i = 0; i < n; i++) {
        student[i].vSchool.resize(k);
        student[i].id = i;
        scanf("%d%d", &student[i].GE, &student[i].GI);
        student[i].Grade = (student[i].GE + student[i].GI) / 2;
        for(int j = 0; j < k; j++) {
            int temp;
            scanf("%d", &temp);
            student[i].vSchool[j] = temp;
        }
    }
    sort(student.begin(), student.end(), cmp1);
    student[0].rank = 1;
    for(int i = 1; i < n; i++) {
        if(student[i].Grade == student[i - 1].Grade && student[i].GE == student[i - 1].GE) {
            student[i].rank = student[i-1].rank;
        } else {
            student[i].rank = student[i-1].rank + 1;
        }
    }
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < k; j++) {
            int schoolID = student[i].vSchool[j];
            int myRank = student[i].rank;
            int myID = student[i].id;
            if(school[schoolID].nowNum < school[schoolID].maxNum || school[schoolID].lastRank == myRank) {
                school[schoolID].nowNum++;
                school[schoolID].lastRank = myRank;
                school[schoolID].stuID.push_back(myID);
                break;
            }
        }
    }
    for(int i = 0; i < m; i++) {
        sort(school[i].stuID.begin(), school[i].stuID.end());
        for(int j = 0; j < school[i].stuID.size(); j++) {
            if(j != 0) printf(" ");
            printf("%d", school[i].stuID[j]);
        }
        printf("\n");
    }
    return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值