A1080

a1080 Graduate Admission (30分)

  • 题目
  • 代码
  • 问题

题目:

It is said that in 2011, there are 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.

代码:

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

typedef struct Applicant
{
	int ge, gi, sum;
	int stu_id;
	int choices[5];
	int rank;
}applicant;
applicant app[40010];
void init_stu(int n)
{
	for (int i = 0;i < n;i++)
		app[i].stu_id = i;
}
//初始化app数组

typedef struct School
{
	int quota;  //招生额度
	int stuNum;  //当前实际招生人数
	int lastAdmit;  //最后一个录取的学生ID
	int id[40010];  //录取的学生编号
}school;
school sch[110];
void init_school(int m)
{
	for (int i = 0;i < m;i++)
	{
		sch[i].stuNum = 0;
		sch[i].lastAdmit = -1;
	}
}
//初始化sch数组

bool cmp(applicant a, applicant b)
{
	if (a.sum != b.sum)
		return a.sum > b.sum;
	else 
		return a.ge > b.ge;
}
bool cmp_id(int a, int b)
{
	return a < b;
}
int main()
{
	int n, m, k;
	scanf("%d %d %d", &n, &m, &k);
	init_stu(n);
	init_school(m);
	int i,j;
	for (i = 0;i < m;i++)
		scanf("%d", &sch[i].quota);
	for (i = 0;i < n;i++)
	{
		scanf("%d %d", &app[i].ge, &app[i].gi);
		for (j = 0;j < k;j++)
			scanf("%d", &app[i].choices[j]);
		app[i].sum = app[i].ge + app[i].gi;
	}
	sort(app, app + n, cmp);
	app[0].rank = 1;
	for (i = 1;i < n;i++)
	{
		if (app[i].sum == app[i - 1].sum&&app[i].ge == app[i - 1].ge)
			app[i].rank = app[i - 1].rank;
		else
			app[i].rank = i + 1;
	}
	for (i = 0;i < n;i++)
	{
		for (j = 0;j < k;j++)
		{
			int num = app[i].choices[j];
            int last=sch[num].lastAdmit;
            int stu_num=sch[num].stuNum;
			if (stu_num < sch[num].quota||(last!=-1&& app[i].rank == app[last].rank))
			{
				sch[num].id[stu_num] = app[i].stu_id;
				sch[num].stuNum++;
				sch[num].lastAdmit = app[i].stu_id;
				break;
			}
		}
	}
	for (i = 0;i < m;i++)
	{
		if (sch[i].stuNum > 0)
		{
			int num = sch[i].stuNum;
			sort(sch[i].id, sch[i].id + num, cmp_id);
			for (j = 0;j < num;j++)
			{
				printf("%d", sch[i].id[j]);
				if (j < num - 1)
					printf(" ");
			}
		}
		printf("\n");
	}
	return 0;
}

运行结果:

部分正确 26/30

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值