#include<cstdio> using namespace std; int main(int argc,char *argv[]) { int m,n; int i,j; int ans,count=0; scanf("%d%d",&m,&n); for(i=0;i<n;i++) { for(j=0;j<m;j++) { int temp; scanf("%d",&temp); if(count==0) { ans=temp; count=1; } else { if(ans==temp) count++; else count--; } } } printf("%d\n",ans); return 0; }解法四:
#include<cstdio> #include<map> using namespace std; int main(int argc,char *argv[]) { int i,j; int m,n; map<int,int> v; scanf("%d%d",&m,&n); for(i=0;i<n;i++) for(j=0;j<m;j++) { int temp; scanf("%d",&temp); v[temp]++; } map<int,int>::iterator it; for(it=v.begin();it!=v.end();it++) if(it->second>m*n/2) break; printf("%d\n",it->first); return 0; }
原文:http://blog.csdn.net/cstopcoder/article/details/22516031