[Questions] AcWing 1566. Graduate Enrollment

Keywords: C C++ Algorithm

;

1566. Graduate Enrollment

Theme transmission: AcWing 1566. Graduate Enrollment

It is said that, 2011 2011 In 2011, Zhejiang Province has about 100 100 100 Graduate Hospitals Ready to Processing 40 , 000 40,000 More than 40,000 applications for admission.

It would be helpful if you could write a program to automate the enrollment process.

Each applicant must provide two results: National Entrance Examination results G E G_E GE and Interview Results G I G_I GI, the applicant's final result is ( G E + G I ) / 2 (G_E+G_I)/2 (GE​+GI​)/2 .

The rules for admission are as follows:

  • Applicants will be ranked from highest to lowest on the basis of their final results and will be enrolled one by one from the top of the ranking list.
  • If the applicant's final results are tied, they are G E G_E GE results are ranked from high to low, and if they remain side by side, the rankings of the side-by-side must be the same.
  • Each applicant can fill in the form K K K volunteers and will be enrolled according to his or her volunteers: if it is a student's turn to be enrolled according to the ranking list and his or her first volunteer school is not full yet, he or she will be successfully enrolled by the school.If the number of places is full, consider other volunteers sequentially until they are successfully enrolled.If the student cannot be enrolled in any of the enrolled schools, the enrollment will fail.
  • If a side-by-side ranking occurs and a side-by-side applicant is applying for the same school, the school must not only enroll a few applicants, but must also enroll all applicants, even if the enrollment limit is exceeded.

Input Format

The first line contains three integers. N N N denotes the total number of applicants, M M M denotes the number of schools, K K K indicates the number of volunteers that can be filled in.

The second line contains M M M integers representing the planned enrollment of each school.

Next N N N rows, each containing 2 + K 2+K 2+K integers, the first two representing an applicant's G E G_E GE and G I G_I GI, Next K K K integers representing the applicant's volunteer school number.

All school numbers 0 ∼ M − 1 0 \sim M-1 0_M_1, all applicant numbers 0 ∼ N − 1 0 \sim N-1 0∼N−1 .

Output Format

Output results for all graduate schools.

Each school has one line of admission results, which contains the applicant numbers for all schools.Numbers must be in ascending order, separated by spaces.

There must be no extra space at the end of each line.

If a school does not enroll any students, blank lines must be output accordingly.

Data Range

1 ≤ N ≤ 40000 1 \le N \le 40000 1≤N≤40000 ,
1 ≤ M ≤ 100 1 \le M \le 100 1≤M≤100 ,
1 ≤ K ≤ 5 1 \le K \le 5 1≤K≤5 ,
0 ≤ G E , G I ≤ 100 0 \le G_E,G_I \le 100 0≤GE​,GI​≤100 ,
No more than planned enrollments per school 2000 2000 2000 .

Input sample:

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

Output sample:

0 10
3
5 6 7
2 8

1 4

Ideas:

Start enrollment from the first volunteer by listing the rankings according to the directions. If the results are side by side, record the schools enrolled. Then join the vector s together to update the enrollment capacity.

Questions:

#include<bits/stdc++.h>

using namespace std;

const int N = 40010, M = 110, K = 5;

int n, m, k;
int cnt[N], wish[N];
vector<int> v[M];

struct Student
{
	int id, score1, score2, sum;
	int wish[K];
	
	bool operator< (const Student &t) const
	{
		if(sum != t.sum)
			return sum > t.sum;
		return score1 > t.score1;
	}
	
	bool operator== (const Student &t) const
	{
		return score1 == t.score1 && score2 == t.score2; 
	}
}s[N];

int main()
{	
	scanf("%d%d%d", &n, &m, &k);
	
	for(int i = 0; i < m; i++)
		scanf("%d", &cnt[i]);
	
	for(int i = 0; i < n; i++)
	{
		s[i].id = i;
		scanf("%d%d", &s[i].score1, &s[i].score2);
		for(int j = 0; j < k; j++)
			scanf("%d", &s[i].wish[j]);
		s[i].sum = s[i].score1 + s[i].score2;
	}
	sort(s, s + n);
	
	memset(wish, -1, sizeof wish);
	for(int i = 0; i < n;)
	{
		int j = i + 1;
		while(j < n && s[i] == s[j])
			j++;
		for(int t = i; t < j; t++)
		{
			for(int u = 0; u < k; u++)
			{
				int w = s[t].wish[u];
				if(cnt[w] > v[w].size())
				{
					wish[t] = w;
					break;
				}
			}
		}
		for(int t = i; t < j; t++)
			if(wish[t] != -1)
				v[wish[t]].push_back(s[t].id);
				
		i = j;			
	}
	
	for(int i = 0; i < m; i++)
	{
		if(v[i].size())
		{
			sort(v[i].begin(), v[i].end());
			printf("%d", v[i][0]);
			for(int j = 1; j < v[i].size(); j++)
				printf(" %d", v[i][j]);
		}
		printf("\n");
	}

	return 0;
}

Posted by jamiet757 on Mon, 06 Sep 2021 09:33:18 -0700