南邮 OJ 1462 Meeting Schedule Arrangement

Meeting Schedule Arrangement

时间限制(普通/Java) :  1000 MS/ 3000 MS          运行内存限制 : 65536 KByte
总提交 : 62            测试通过 : 33 

比赛描述

Mr. Trasapong, the head of Computer Engineering Department, would like to have a meeting as soon as possible to address some issues of the department. However, other members in his department are so busy that it is very difficult to arrange their schedules for the meeting. So, in order to settle the meeting date, he requested every member to send back a list of convenient dates by E-mail. Your mission is to help him by writing a program that chooses the best date from the submitted lists. Your program should find the most convenient date for the most of the members. If there is more than one such day, the earliest is the best.



输入

The input has multiple data sets, each starting with a line containing the number of members in the department and the quorumof the meeting.

NQ

Here, N, meaning the number of the members in the department, and meaning the quorum, are positive integers. is less than 20, and, of course, is less than or equal to N.

lines follow, each describing convenient dates for a member in the following format.M DateDate... DateM

Here, means the number of convenient dates for the member, which is an integer greater than or equal to zero. The remaining items in the line are his/her dates of convenience, which are positive integers less than 31, that is, 1 means tomorrow, 2 means the day after tomorrow, and so on. They are in ascending order without any repetition and separated by a space character. Lines have neither leading nor trailing spaces.

A line containing two zeros indicates the end of the input. 

输出

For each data set, print a single line containing the date number convenient for the largest number of members. If there is more than one such date, print the earliest. However, if no dates are convenient for more than or equal to the quorum number of members, print 0 instead. 

样例输入

3 2
2 1 4
0
3 3 4 8
3 2 
4 1 5 8 9 
3 2 5 9 
5 2 4 5 7 9 
3 3
2 1 4 
3 2 5 9 
2 2 4
3 3
2 1 2 
3 1 2 9 
2 2 4
0 0

样例输出

4


2

提示

Note: quorum means the smallest number of the people who must present at a meeting. 

用于NUPT ACM 2010 Personal Ranking Contest 5


题目来源

ACM-ICPC Thailand Southern Area Programming Contest 2010




#include<iostream>
#include<string>
using namespace std;
int main(){
	int N,Q,M,i,num,a[32],maxIndex;
	while(cin>>N>>Q && (N||Q)){
		for(i=1; i<32; i++){
			a[i] = 0;
		}
		for(i=0; i<N; i++){
			cin>>M;
			while(M--){
				cin>>num;
				a[num]++;
			}
		}
		num = 0;
		maxIndex = 0;
		for(i=1; i<32; i++){
			if(a[i]>num){
				num = a[i];
				maxIndex = i;
			}
		}
		if(num && num>=Q){
			printf("%d\n",maxIndex);
		}else{
			printf("0\n");
		}
	}
}





你可能感兴趣的:(schedule,ACM,arr,Meeting,南邮OJ)