PAT甲级1080

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
#include
#include
#include
#include
#include
using namespace std;
struct stu
{
	int ID, GE, GI,rank;
	vector choices;
	int sum()
	{
		return GE + GI;
	}
	bool operator<(stu s)
	{
		if (sum() != s.sum())
			return sum() > s.sum();
		else
			return GE > s.GE;
	}
};//重载小于号制定比较规则
int main()
{
	int N, M, K;
	cin >> N >> M >> K;
	vector quota; int QUOTA;
	for (int i = 0; i < M; i++)
	{
		cin >> QUOTA;
		quota.push_back(QUOTA);
	}//存储各个学校的指标
	stu st; int choice; vector v;
	for (int i = 0; i < N; i++)
	{
		st.ID = i;
		cin >> st.GE >> st.GI;
		st.choices.clear();
		for (int j = 0; j < K; j++)
		{
			cin >> choice;
			st.choices.push_back(choice);
		}
		v.push_back(st);
	}//将每个学生的填报情况存储到容器中
	sort(v.begin(), v.end());//将学生按照分数非递增排序
	int oldrank = 1;
	for (int i = 0; i < v.size(); i++)
	{
		if (!i || v[i].sum() == v[i - 1].sum()&& v[i].GE == v[i - 1].GE)
		{
			v[i].rank = oldrank;
		}
		else
		{
			v[i].rank = i + 1;
			oldrank = i + 1;
		}
	}//对学生进行排名,注意所写代码一定要能够完全反映题意
	vector *schooladmissionResult = new vector[M];//为每个学校设一个录取信息容器
	int i = 0; int firststurank,firstschool;//这个是为了处理同名次并且报同一学校的问题
	bool flag = false;//若该同学已被录取直接处理下一个同学
	while (i < N)
	{
		flag = false;
		for (int j = 0; j  temp)
				{
					quota[school] -= temp; 
				}
				else
					quota[school] = 0;
				if (temp)
				{
					i += temp;
				}
					i++;
			}
			if (flag)
				break;
			if (j == K - 1)//该学生所填志愿没被任何学校录取
				i++;
		}
	}
/*上面的while循环反映了录取过程,简要说明一下。首先是从高分往低分开始录,并不是按照志愿优先原则,而是分高是王道。
处理每一个学生的录取过程是这样的:先从他的第一志愿开始,如果所填学校还有名额那就可以让他被录。并且从他的后面开始
检查是不是有跟他名次一样且报同一个学校的。当然这个地方有点问题,那就是相同名次的人可能报同一个学校的志愿级别不同,
可能前一个报的是第一志愿,后一个报的是第二志愿。但本题应该说是相同级别志愿,也就是同一名次,同一志愿级别,同一学校
否则还要对学生的志愿进行遍历。然后对指针i根据出现这样情况的人数进行调整即可。如果一个人填报的所有的志愿学校名额都
没有,那么直接对后一个学生进行遍历*/
	for (int i = 0; i < M; i++)
	{
		if (schooladmissionResult[i].size())
		{
			sort(schooladmissionResult[i].begin(), schooladmissionResult[i].end());
			for (int j = 0; j < schooladmissionResult[i].size(); j++)
			{
				cout << schooladmissionResult[i][j];
				if (j != schooladmissionResult[i].size() - 1)
					cout << " ";
				else
					cout << endl;
			}
		}
		else
			cout << endl;
	}
	return 0;
}

你可能感兴趣的:(PAT)