1、题意:
给出N个平面上的点。保证每一个点的坐标都是正奇数。
你要在平面上画两条线,一条是x=a,一条是y=b,且a和b都是偶数。
直线将平面划成4个部分,要求包含点数最多的那个部分点数最少。
2、分析:我们首先二分答案。。。然后我们枚举横着在哪里切开,用两个树状数组维护上下界,
       保证四个框框都在mid之内。
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
using namespace std;
#define M 100010

inline int read(){
    char ch = getchar(); int x = 0, f = 1;
    while(ch < '0' || ch > '9'){
        if(ch == '-') f = -1;
        ch = getchar();
    }
    while('0' <= ch && ch <= '9'){
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    return x * f;
}

struct Node{
    int x, y;

    inline bool operator < (const Node& rhs) const{
        return y < rhs.y;
    }
} a[M];
pair<int , int> li[M];
int C[2][M], tt;
int n;

inline void change(int c[], int x, int y){
    for(; x <= n; x += (x & -x)) c[x] += y;
}

inline int query(int c[], int x){
    int res = 0;
    for(; x > 0; x -= (x & -x)) res += c[x];
    return res;
}

inline bool check(int x){
    int size0 = n, size1 = 0;
    memset(C, 0, sizeof(C));
    for(int i = 1; i <= n; i ++) change(C[0], a[i].x, 1);
    int it0 = 1, it1 = n;
    for(int t, j = 1, i = 1; i <= n; i = j){
        while(a[j].y == a[i].y){
            change(C[0], a[j].x, -1), size0 --;
            change(C[1], a[j].x, 1), size1 ++; j ++;
        }
        while(it0 <= n && query(C[0], it0) <= x) it0 ++; it0 --;
        while(it1 > 0 && query(C[1], it1) > x) it1 --;
        t = min(it0, it1);
        if(size0 - query(C[0], t) <= x && size1 - query(C[1], t) <= x) return 1;
    }
    return 0;
}

int main(){
    n = read();
    for(int i = 1; i <= n; i ++) a[i].x = read(), a[i].y = read(), li[i].first = a[i].x, li[i].second = i;
    sort(li + 1, li + n + 1);
    tt = 0;
    li[0].first = -2147483647;
    for(int i = 1; i <= n; i ++){
        if(li[i].first != li[i - 1].first) tt ++;
        a[li[i].second].x = tt;
    }
    sort(a + 1, a + n + 1);
    int l = 1, r = n, ans = n;
    while(l <= r){
        int mid = (l + r) / 2;
        if(check(mid)) r = (ans = mid) - 1;
        else l = mid + 1;
    }
    printf("%d\n", ans);
    return 0;
}

BZOJ4411——[Usaco2016 Feb]Load balancing的更多相关文章

  1. [bzoj4411] [Usaco2016 Feb]Load balancing

    先离散化一下(也可以不用 枚举横坐标,用线段树维护两边纵坐标上的节点数. 每次在线段树上二分...(感觉似乎树状数组也行? #include<cstdio> #include<ios ...

  2. bzoj千题计划180:bzoj4411: [Usaco2016 Feb]Load balancing

    http://www.lydsy.com/JudgeOnline/problem.php?id=4411 用树状数组维护扫描线 一个树状数组维护扫描线之上的y<=i点,另一个维护扫描线之下y&l ...

  3. BZOJ 4411: [Usaco2016 Feb]Load balancing 线段树+二分

    code: #include <bits/stdc++.h> #define N 100060 #define M 1000000 #define lson x<<1 #def ...

  4. bzoj4409&&bzoj4410&&bzoj4411[Usaco2016 Feb Platinum]题解

    辣鸡wyz最近状态奇差,于是想用usaco题找找手感,万万没想到被虐了一脸TAT 先贴代码,有空再填坑 4409[Usaco2016 Feb]Circular barn #include <io ...

  5. 【架构】How To Use HAProxy to Set Up MySQL Load Balancing

    How To Use HAProxy to Set Up MySQL Load Balancing Dec  2, 2013 MySQL, Scaling, Server Optimization U ...

  6. CF# Educational Codeforces Round 3 C. Load Balancing

    C. Load Balancing time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  7. Codeforces Educational Codeforces Round 3 C. Load Balancing 贪心

    C. Load Balancing 题目连接: http://www.codeforces.com/contest/609/problem/C Description In the school co ...

  8. UVA 12904 Load Balancing 暴力

    Load Balancing Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/vi ...

  9. Load Balancing 折半枚举大法好啊

    Load Balancing 给出每个学生的学分.   将学生按学分分成四组,使得sigma (sumi-n/4)最小.         算法:   折半枚举 #include <iostrea ...

随机推荐

  1. Java 毫秒转换为日期类型、日期转换为毫秒

    /毫秒转换为日期 public static void main(String[] args) { DateFormat formatter = new SimpleDateFormat(" ...

  2. C#中使用代码动态改变配置文件信息

    static void Main(string[] args) { XmlDocument xDoc = new XmlDocument(); xDoc.Load("../../App.co ...

  3. select()

    select(),确定一个或多个套接口的状态,本函数用于确定一个或多个套接口的状态,对每一个套接口,调用者可查询它的可读性.可写性及错误状态信息,用fd_set结构来表示一组等待检查的套接口,在调用返 ...

  4. 20145212 实验三《敏捷开发与XP实践》

    20145212 实验三<敏捷开发与XP实践> 实验内容 使用git上传代码 与20145223同学一组,使用git相互更改代码 同组实验报告链接:http://www.cnblogs.c ...

  5. Java关键字——instanceof

    Java中可以使用instanceof关键字判断一个对象到底是哪一个类的实例 格式:对象 instance 类 返回 boolean类型 通过子类实例化的对象同时是子类和父类的实例,无论是直接声明子类 ...

  6. Android学习笔记——button_activity

    工程的功能是实现在一个acticity上点击按钮,切换到另外一个activity 以下代码为MainActivity.java中的代码 package com.example.button_activ ...

  7. centos6.5编译安装git

    1.下载高版本的git,地址:https://github.com/git/git/release,选择git-2.9.3.tar.gz 2.安装依赖包.解压.编译安装 yum install cur ...

  8. -- c语言数据类型总结 --

    C语言中的数据类型总结

  9. 浅谈JavaScript中的能力检测

    引言 我们知道,各个版本的浏览器有着许多不一致性.理想状态下,应该是所有的浏览器都提供一套标准的API接口.但是现实中,各个版本的浏览器存在的怪癖非常多,我们通常都是使用客户端检测来作为补救措施.但是 ...

  10. [工具]json转类

    摘要 这周在园子看到一篇介绍JsonCSharpClassGenerator这个工具的文章,感觉挺实用的,在现在项目中json用的是最多的,所以在转换对应的类的时候,确实挺频繁,所以就研究了一下这个工 ...