ZOJ 1715 When Can We Meet?
来源:互联网 发布:2016新款羊绒衫淘宝网 编辑:程序博客网 时间:2024/05/18 18:14
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
int main()
{
int N,Q;
int M;
int i,j;
while(scanf("%d",&N)&&scanf("%d",&Q))
{
int t,max,max_i=1;
if(N==0&&Q==0)
break;
int a[101]={0};
for(i=0;i<N;i++)
{
scanf("%d",&M);
for(j=0;j<M;j++)
{
scanf("%d",&t);
a[t]++;
}
}
max=a[1];
for(i=2;i<=100;i++)
{
if(a[i]>max)
{
max=a[i];
max_i=i;
}
}
printf("%d\n",max>=Q?max_i:0);
}
return 0;
}
//用t代表哪一天有空,a[t]代表那一天出现的次数,注意数组要大,不然时间会超限。。还有定义a[100]的话a[100]无意义
- ZOJ 1715 When Can We Meet?
- zoj 1715 When Can We Meet?
- ZOJ 1715 When Can We Meet?
- 1715 When Can We Meet?
- zoj 1715 When Can We Meet?(水~)
- zoj 1751 When Can We Meet?
- 2028 When Can We Meet?
- (简单)When Can We meet?
- zoj1715---------------------When Can We Meet?
- poj2028 When Can We Meet?
- poj2028 When Can We Meet?
- POJ2028 When Can We Meet?
- POJ2028 When Can We Meet? 水题
- 北大ACM poj2028 When Can We Meet?
- POJ 2028 When can we meet?
- poj 2028 When Can We Meet?
- POJ2028——When Can We Meet?
- POJ 2028 When Can We Meet? 枚举
- JMX : Standard MBean
- 上下午的判断
- C#处理word事件
- 制作U盘Linux 与WinPE启动
- linux下configure命令详细介绍
- ZOJ 1715 When Can We Meet?
- VS2008下用MFC 的MSComm控件编写串口程序
- NoSQL是什么
- Fedora 安装 skyeye
- matlab2010b所有的工具箱目录
- SQL语句的添加、删除、修改多种方法
- php 扩展库禁用最简单方法
- POJ 1065 Wooden Sticks 贪心
- 人,活着就要有一身价值