复习版
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#define not !
#define and &&
#define or ||
#define ri register int
#define rep(inc, frm, to) for (ri inc = frm; inc < (to); ++inc)
#define rep2(inc, frm, to) for (ri inc = frm; inc > (to); --inc)
typedef long long int ll;
#define r() fast_read()
bool is_digit(const char c) {
return c >= 48 and c <= 57;
}
ll fast_read(void) {
ll n = 0, sign = 1;
char c = getchar();
while (not is_digit(c)) {
if (c == '-') sign = ~0;
c = getchar();
}
while (is_digit(c)) {
n = (n << 1) + (n << 3) + (c ^ 48);
c = getchar();
}
return sign * n;
}
int cnts[1 << 24];
signed main(int argc, char const *argv[]) {
int n = r(), m = r(), color;
rep(y, 0, m) rep(x, 0, n) {
color = r();
if (++cnts[color] > (n * m) >> 1) {
printf("%d\n", color);
return 0;
}
}
return ~~(0 ^ 0);
}
HashTable Again!
#include <iostream>
#include <unordered_map>
using namespace std;
int m, n, id;
unordered_map<int, int> freq;
int main(int argc, char** argv) {
cin >> m >> n;
for (int y = 0; y < m; ++y)
for (int x = 0; x < n; ++x) {
cin >> id;
if (++freq[id] > (m * n) >> 1)
return printf("%d\n", id), 0;
}
return 0;
}