#include <stdio.h>
#include <vector>
#include <algorithm>
#define MAX 1<<26
using namespace std;
int color[MAX] = {0};
bool cmp(int a, int b) {
return color[a] > color[b];
}
int main(int argc, char *argv[]) {
int m, n;
scanf("%d %d", &m, &n);
int i, j;
vector<int> v;
int in;
for (i = 0; i < n; i++) {
for (j = 0; j < m; j++) {
scanf("%d", &in);
if (color[in] == 0) {
v.push_back(in);
}
color[in]++;
}
}
sort(v.begin(), v.end(), cmp);
if (color[v.front()] * 2 > m * n) {
printf("%d\n", v.front());
}
return 0;
}
【PAT甲级】1054. The Dominant Color (20)
最新推荐文章于 2022-04-18 12:51:18 发布