码迷,mamicode.com
首页 > 其他好文 > 详细

POJ 2028 When Can We Meet?

时间:2015-05-28 12:27:17      阅读:146      评论:0      收藏:0      [点我收藏+]

标签:

Time Limit: 1000MS   Memory Limit: 30000K
Total Submissions: 5158   Accepted: 2844

Description

The ICPC committee would like to have its meeting as soon as possible to address every little issue of the next contest. However, members of the committee are so busy maniacally developing (possibly useless) programs that it is very difficult to arrange their schedules for the meeting. So, in order to settle the meeting date, the chairperson requested every member to send back a list of convenient dates by E-mail. Your mission is to help the chairperson, who is now dedicated to other issues of the contest, by writing a program that chooses the best date from the submitted lists. Your program should find the date convenient for the most members. If there is more than one such day, the earliest is the best.

Input

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

N Q
Here, N, meaning the size of the committee, and Q meaning the quorum, are positive integers. N is less than 50, and, of course, Q is less than or equal to N.

N lines follow, each describing convenient dates for a committee member in the following format.

M Date1 Date2 ... DateM
Here, M 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 100, 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.

Output

For each data set, print a single line containing the date number convenient for the largest number of committee 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.

Sample Input

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

Sample Output

4
5
0
2

CODE:
#include <iostream>
#include <cstdio>
#include <cstring>
#define REP(i, s, n) for(int i = s; i <= n; i ++)
#define REP_(i, s, n) for(int i = n; i >= s; i --)
#define MAX_N 100 + 10

using namespace std;

int main(){
    int n, q, date[MAX_N];
    while(scanf("%d%d", &n, &q) != EOF){
        if(n == 0 && q == 0) break;
        int m, x, mdate = 0;
        memset(date, 0, sizeof(date));
        REP(i, 1, n){
            scanf("%d", &m);
            REP(i, 1, m){
                scanf("%d", &x), date[x] ++;
                if(x > mdate) mdate = x;
            }
        }
        int ans = 0;
        REP(i, 1, mdate){
            if(date[i] > date[ans]) ans = i;
        }
        if(date[ans] >= q) printf("%d\n", ans);
        else printf("0\n");
    }
    return 0;
}

 


POJ 2028 When Can We Meet?

标签:

原文地址:http://www.cnblogs.com/ALXPCUN/p/4535478.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!