shunfurh 于 2017.09.18 11:20 提问

When Can We Meet?

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

1个回答

caozhy      2017.10.02 23:46

poj2028 When Can We Meet?
2028题要求先读入两个数字，第一个表示总人数，第二个表示开始会议的最低人数，然后依次读入每个人的日期，统计找出最近的符合要求的日子并输出，没有则输出0。 我的思路是将日期统计存入一个数组，数组下标号对应日期，然后扫描数组获取最大值，再扫一遍数组，找到对应的日期输出。感觉还是有点繁，最后应该一边扫一遍就行。 #include #include void main(){ char s[202
1715 When Can We Meet?
#include int main() { int n,q,m,date,max,i; int a[100]; while(scanf("%d%d",&n,&q)&&n){ for(i = 0;i<100;i++) a[i] = 0; while(n--){ scanf("%d",&m); while(m--){ scanf("%d",&date);
POJ2028——When Can We Meet?
When Can We Meet? Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 5461   Accepted: 2994 Description The ICPC committee would like to have its meeting as soon
when can we meet POJ-2028
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 u
(简单)When Can We meet?
#include #include #include #include #include using namespace std; int main() { freopen("fuck.txt","r",stdin); int i,j,k; int n; while (cin>>n>>k,n) { int go[101]={0}; while (n--) { c
POJ2028 When Can We Meet?

2028 When Can We Meet?
<br />这个题虽然挺简单的，但是这个题的思路挺好的，有必要记下来。思路是：将每个人的日期记在一个一维数组里，求得每个日期有多少人参加，从该数组中找第一个最大的值，并且该值必须大于q，则该值就是所要求的值，如果没有这样的值，就输出0。代码如下：<br />#include "stdio.h" #include "string.h" int main() { freopen("in.txt","r",stdin); int n,q; int i,j,k; int m[101]; w
POJ 2028 When Can We Meet?（模拟）
When Can We Meet? 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 s
poj 2028 When Can We Meet?

zoj 1751 When Can We Meet?
#include "iostream" #include "memory.h" #include "algorithm" using namespace std; int num[100]; int ans[100]; int main() { int committe, quorum, M, i, j, temp1, temp2; bool tag; while (cin >> com