A1054 The Dominant Color

题目很简单,用map省空间,如果直接开很大的数组统计数字出现次数,不知道会不会爆内存,毕竟数字到了2^24.
没必要开二维数组,反正空间都是m*n。

#include <stdio.h>
#include <map>
using namespace std;

int main(int argc, char const *argv[])
{
	int m,n;
	scanf("%d%d",&m,&n);
	int color;
	map<int,int> mp;
	for(int i=0;i<m*n;i++){
		scanf("%d",&color);
		mp[color]++;
	}
	for(map<int,int>::iterator it=mp.begin();it!=mp.end();it++){
		if(it->second > m*n/2){
			printf("%d",it->first);
			break;
		}
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_43108373/article/details/84193436