Gym 331746H Load Balancing

题目链接:Gym 331746H Load Balancing

题目大意:

题解:
将各点按照(x)(y)分别排序后,暴力枚举横竖切线。

#include <algorithm>
#include <iostream>
using namespace std;

struct node {
    int x, y;
} a[1010], b[1010];
int c[1010], top;
int n, m, ans = 0x7fffffff;
bool cmp1(node u, node v) { return u.x < v.x; }
bool cmp2(node u, node v) { return u.y < v.y; }

void find(int row) {
    int l, r, L, R, now = 1;
    l = r = L = R = 0;
    for (int i = 1; i <= n; ++i) {
        if (a[i].x < row) {
            l++;
        } else {
            r++;
        }
    }
    for (int i = 1; i <= top; i++) {
        int col = c[i] + 1;
        while (now <= n && b[now].y <= col) {
            if (b[now].x < row) {
                L++;
            } else {
                R++;
            }
            now++;
        }
        ans = min(ans, max(max(L, l - L), max(R, r - R)));
    }
}

int main() {
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i].x >> a[i].y;
        b[i] = a[i];
    }
    sort(a + 1, a + n + 1, cmp1);
    sort(b + 1, b + n + 1, cmp2);
    for (int i = 1; i <= n; ++i) {
        if (b[i].y != c[top]) {
            c[++top] = b[i].y;
        }
    }
    for (int i = 1; i <= n; ++i) {
        if (a[i].x != a[i - 1].x) {
            find(a[i].x + 1);
        }
    }
    cout << ans;
    return 0;
}
原文地址:https://www.cnblogs.com/IzumiSagiri/p/15220773.html