POJ2028 When Can We Meet?

仔细看题就知道这个题关键就是找几个数组的公共元素的最大值

这里可以用哈希表的方法做出来!

重要的事情说三遍

哈希表!

哈希表!

哈希表!

原理就是把对应的数值作为下标映射到哈希表里面去,如果每次进来一个数值就对相应的哈希表+1这个不失为一种好方法,对于传统的都可以解决 - -

然后给上代码即可了 - -

#include <iostream>
using namespace std;
int hash[101];
int main(){
    int m,n;
    while(cin>>m>>n &&m*n!=0){
        memset(hash,0,sizeof(hash));
        for(int j=0;j<m;j++){
            int k,temp;
            cin>>k;
            for(int i=0;i<k;i++){
                cin>>temp;
                hash[temp]++;
            }
        }
        /*for(int temp=0;temp<101;temp++){
            cout<<hash[temp]<<" ";
        }*/
        int max = 0,pos=0;
        for(int i=0;i<101;i++){
            if(hash[i]>max){
                max= hash[i];
                pos = i;
            }
        }
        if(max>=n){
            cout<<pos<<endl;
        }
        else cout<<"0"<<endl;
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值