添加链接描述
注意unordered_map 测试点2
#include<bits/stdc++.h>
using namespace std;
const int N=1e4+9;
int arr[N];
int res[N];
typedef pair<int,int> pii;
bool cmp(pii a,pii b){
return a.second>b.second;
}
int main(){
int n,m;
cin>>n>>m;
for(int i=1;i<=m;i++){
unordered_map<int,int>mp;
pii now[N];
for(int j=1;j<=n;j++){
cin>>arr[j];
mp[arr[j]]++;
}
for(int j=1;j<=n;j++){
int x=mp[arr[j]];
int y=n-x;
now[j]={j,y};
}
sort(now+1,now+1+n,cmp);
int gg=now[1].second;
for(int j=1;j<=n;j++){
if(now[j].second==gg){
res[now[j].first]++;
}
}
}
int mx=0,fake=0;
for(int i=1;i<=n;i++){
if(mx<res[i]){
mx=res[i];
fake=i;
}
}
cout<<fake<<endl;
return 0;
}