返回目录![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/0bfa9ea9a37026f8bb6cf93a2b19acdf.png)
题意
给出n行m列的数字矩阵,求其中超过半数的数字
样例(可复制)
5 3
0 0 255 16777215 24
24 24 0 0 24
24 0 24 24 24
//output
24
注意点
- 如果使用数组来进行计数,由于数据量大,可能内存溢出
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,m,k,maxx=0;
map<int,int> count;
cin>>n>>m;
n*=m;
while(n--){
scanf("%d",&m);
if(count.find(m)!=count.end())count[m]++;
else count[m]=1;
}
for(map<int,int>::iterator it=count.begin();it!=count.end();it++){
if(it->second>maxx){
k=it->first;
maxx=it->second;
}
}
cout<<k<<endl;
return 0;
}