POJ 2028 When Can We Meet?

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;
}
				
时间: 2024-10-07 15:47:09

POJ 2028 When Can We Meet?的相关文章

POJ 2028 When Can We Meet? (又是一道水题)

[题目简述]:N代表有几个会员,Q代表有几个会员的时候开会才算做有效,接下来N行,每行第一个数字代表这行有M个数,说明这个会员在哪几天有时间.最后让我们求出  最快  哪天开会. [分析]:简单题,见代码. // 248K 47Ms #include<iostream> using namespace std; int M[101]; int N,Q; int main() { int m; int m1; while(1) { cin>>N>>Q; if(N == 0

POJ 2028

#include <iostream> #define MAXN 200 using namespace std; int mark[MAXN]; int main() { //freopen("acm.acm","r",stdin); int m; int n; int i; int j; int team; int tem; int _max; int ans; while(cin>>m>>n,m||n) { _max = -

ACM训练方案-POJ题目分类

ACM训练方案-POJ题目分类 博客分类: 算法 ACM online Judge 中国: 浙江大学(ZJU):http://acm.zju.edu.cn/ 北京大学(PKU):http://acm.pku.edu.cn/JudgeOnline/ 杭州电子科技大学(HDU):http://acm.hdu.edu.cn/ 中国科技大学(USTC):http://acm.ustc.edu.cn/ 北京航天航空大学(BUAA)http://acm.buaa.edu.cn/oj/index.php 南京

转载:poj题目分类(侵删)

转载:from: POJ:http://blog.csdn.net/qq_28236309/article/details/47818407 按照ac的代码长度分类(主要参考最短代码和自己写的代码) 短代码:0.01K–0.50K:中短代码:0.51K–1.00K:中等代码量:1.01K–2.00K:长代码:2.01K以上. 短:1147.1163.1922.2211.2215.2229.2232.2234.2242.2245.2262.2301.2309.2313.2334.2346.2348

poj题库分类

初期:一.基本算法:     (1)枚举. (poj1753,poj2965)     (2)贪心(poj1328,poj2109,poj2586)     (3)递归和分治法.     (4)递推.     (5)构造法.(poj3295)     (6)模拟法.(poj1068,poj2632,poj1573,poj2993,poj2996)二.图算法:     (1)图的深度优先遍历和广度优先遍历.     (2)最短路径算法(dijkstra,bellman-ford,floyd,hea

POJ题目(转)

http://www.cnblogs.com/kuangbin/archive/2011/07/29/2120667.html 初期:一.基本算法:     (1)枚举. (poj1753,poj2965)     (2)贪心(poj1328,poj2109,poj2586)     (3)递归和分治法.     (4)递推.     (5)构造法.(poj3295)     (6)模拟法.(poj1068,poj2632,poj1573,poj2993,poj2996)二.图算法:     (

Poj 题目分类

初期:一.基本算法:     (1)枚举. (poj1753,poj2965)     (2)贪心(poj1328,poj2109,poj2586)     (3)递归和分治法.     (4)递推.     (5)构造法.(poj3295)     (6)模拟法.(poj1068,poj2632,poj1573,poj2993,poj2996)二.图算法:     (1)图的深度优先遍历和广度优先遍历.     (2)最短路径算法(dijkstra,bellman-ford,floyd,hea

POJ题目分类(转)

初期:一.基本算法:     (1)枚举. (poj1753,poj2965)     (2)贪心(poj1328,poj2109,poj2586)     (3)递归和分治法.     (4)递推.     (5)构造法.(poj3295)     (6)模拟法.(poj1068,poj2632,poj1573,poj2993,poj2996)二.图算法:     (1)图的深度优先遍历和广度优先遍历.     (2)最短路径算法(dijkstra,bellman-ford,floyd,hea

北大POJ题库使用指南

原文地址:北大POJ题库使用指南 北大ACM题分类主流算法: 1.搜索 //回溯 2.DP(动态规划)//记忆化搜索 3.贪心 4.图论 //最短路径.最小生成树.网络流 5.数论 //组合数学(排列组合).递推关系.质因数法 6.计算几何 //凸壳.同等安置矩形的并的面积与周长.凸包计算问题 8.模拟 9.数据结构 //并查集.堆.树形结构 10.博弈论 11.CD有正气法题目分类: 1. 排序 1423, 1694, 1723, 1727, 1763, 1788, 1828, 1838, 1