페이지

5884번: 감시 카메라

https://www.acmicpc.net/problem/5884


#include<cstdio>
#include<map>
#include<algorithm>
using namespace std;
const int MXN = 5e4;
int x[MXN], y[MXN], ck[MXN], n;
bool comp(pair<intint> i, pair<intint> j) { return i.second < j.second; }
int main() {
    scanf("%d", &n);
    for (int i = 0; i < n; i++) scanf("%d %d", x + i, y + i);
    for (int i = 0; i < 3; i++) {
        map<intint> mp1, mp2;
        for (int i = 0; i < n; i++) if (!ck[i]) mp1[x[i]]++, mp2[y[i]]++;
        map<intint>::iterator it1 = max_element(mp1.begin(), mp1.end(), comp),
            it2 = max_element(mp2.begin(), mp2.end(), comp);
        if (it1 == mp1.end()) continue;
        if (it1->second > it2->second) {
            for (int i = 0; i < n; i++) if (x[i] == it1->first) ck[i] = 1;
        }
        else for (int i = 0; i < n; i++) if (y[i] == it2->first) ck[i] = 1;
    }
    int i;
    for (i = 0; i < n; i++)if (!ck[i]) {
        puts("0");
        break;
    }
    if (i == n) puts("1");
    return 0;
}

댓글 없음 :

댓글 쓰기