1.链接地址
https://vjudge.net/problem/POJ-2028
2.问题描述
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.
输入样例
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 5 0 2
3.解题思路
模拟水题,设定一个参数num,表示在该日期有空的参会员的个数,然后比较求出最大值
4.算法实现源代码
#include <stdio.h> #include <stdlib.h> #include <string.h> #define Max 110 int num[Max]; int n,m; int max_int,index; int main() { while(scanf("%d%d",&n,&m),n) { memset(num,0,sizeof(num)); max_int=0; for(int i=1;i<=n;i++) { int number,data; scanf("%d",&number); for(int j=1;j<=number;j++) { scanf("%d",&data); num[data]++; if(num[data]>max_int) { max_int=num[data]; index=data; } else if(num[data]==max_int && index>data) index=data; } } if(max_int<m) printf("0\n"); else printf("%d\n",index); } return 0; }
浙公网安备 33010602011771号