• 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;
    }
    
  • 相关阅读:
    jquery在线手册
    bootstrap学习之路
    实用的cmd命令
    在源代码中插入防止盗版代码片段的方式
    常用的正则表达式
    仿站步骤
    thinkphp 公用函数
    php switch判断一个数所在的范围
    ps学习教程
    九度oj 题目1185:特殊排序
  • 原文地址:https://www.cnblogs.com/IzumiSagiri/p/15220773.html
Copyright © 2020-2023  润新知