因为题目中给的数值太大,用hash可能会比较耗时和占内存,可以考虑采用map
#include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
map <int,int> a;
int main()
{
int m,n;
cin>>m>>n;
for (int i=0;i<n;i++)
{
for (int j=0;j<m;j++)
{
int temp;
scanf("%d",&temp);
if(a.find(temp)!=a.end())
a[temp]++;
else
a[temp]=1;
}
}
int ans,max=0;
for (auto it=a.begin();it!=a.end();it++)
{
if(it->second>max)
{
max=it->second;
ans=it->first;
}
}
cout<<ans;
}
本文介绍了一种利用Map数据结构优化大数据处理效率的方法,通过实例演示了如何在面对大规模数值输入时,避免使用Hash,转而采用Map来提高查找速度和节省内存。文章详细解释了Map的使用过程,并提供了完整的代码示例。
1912

被折叠的 条评论
为什么被折叠?



