POJ 2028 When Can We Meet?(我的水题之路——边输入,边搜索)

来源:互联网 发布:linux vps speedtest 编辑:程序博客网 时间:2024/06/05 17:32
When Can We Meet?
Time Limit: 1000MS Memory Limit: 30000KTotal Submissions: 3489 Accepted: 1934

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 22 1 403 3 4 83 24 1 5 8 93 2 5 95 2 4 5 7 93 32 1 43 2 5 92 2 43 32 1 23 1 2 92 2 40 0

Sample Output

4502

Source

Japan 2003 Domestic

有N个会议,最多可以在同一天有Q个会议。接下来对于N个会议,会给出每个会议开会的时间列表。问,开会时间最近的,且在同一天开会数量大于等于Q,且最大的会议数量的那天日期,输出。

用一个a数组,存储每一天的会议数量,然后搜索出开会数量大于等于Q且最大的那天的日期,如果开会数量相同,则取最近的那天日期。

注意点:
1)当取得最大数量的时候,要取最近开会的时间。(1WA)
2)同一天开会数量如果小于Q,则条件不成立。

代码(1AC 1WA):
#include <cstdio>#include <cstdlib>#include <cstring>int a[110];int main(void){    int N, Q;    int day, days, i, j;    int min, max;    int flag = 0;    while (scanf("%d%d", &N, &Q), Q != 0 || N != 0){        flag = 0;        memset(a, 0, sizeof(a));        min = 10000;        max = -1;        for (i = 0; i < N; i++){            scanf("%d", &day);            for (j = 0; j < day; j++){                scanf("%d", &days);                a[days] ++;                if (a[days] >= Q){                    flag = 1;                    if (max < a[days]){                        max = a[days];                        min = days;                    }                    if (a[days] == max && min > days){                        min = days;                        max = a[days];                    }                }            }        }        if (flag == 1){            printf("%d\n", min);        }        else{            printf("0\n");        }    }    return 0;}


原创粉丝点击