1、题意:
给出N个平面上的点。保证每一个点的坐标都是正奇数。
你要在平面上画两条线,一条是x=a,一条是y=b,且a和b都是偶数。
直线将平面划成4个部分,要求包含点数最多的那个部分点数最少。
2、分析:我们首先二分答案。。。然后我们枚举横着在哪里切开,用两个树状数组维护上下界,
       保证四个框框都在mid之内。
  1. #include <cstdio>
  2. #include <cstring>
  3. #include <cstdlib>
  4. #include <algorithm>
  5. using namespace std;
  6. #define M 100010
  7.  
  8. inline int read(){
  9. char ch = getchar(); int x = 0, f = 1;
  10. while(ch < '0' || ch > '9'){
  11. if(ch == '-') f = -1;
  12. ch = getchar();
  13. }
  14. while('0' <= ch && ch <= '9'){
  15. x = x * 10 + ch - '0';
  16. ch = getchar();
  17. }
  18. return x * f;
  19. }
  20.  
  21. struct Node{
  22. int x, y;
  23.  
  24. inline bool operator < (const Node& rhs) const{
  25. return y < rhs.y;
  26. }
  27. } a[M];
  28. pair<int , int> li[M];
  29. int C[2][M], tt;
  30. int n;
  31.  
  32. inline void change(int c[], int x, int y){
  33. for(; x <= n; x += (x & -x)) c[x] += y;
  34. }
  35.  
  36. inline int query(int c[], int x){
  37. int res = 0;
  38. for(; x > 0; x -= (x & -x)) res += c[x];
  39. return res;
  40. }
  41.  
  42. inline bool check(int x){
  43. int size0 = n, size1 = 0;
  44. memset(C, 0, sizeof(C));
  45. for(int i = 1; i <= n; i ++) change(C[0], a[i].x, 1);
  46. int it0 = 1, it1 = n;
  47. for(int t, j = 1, i = 1; i <= n; i = j){
  48. while(a[j].y == a[i].y){
  49. change(C[0], a[j].x, -1), size0 --;
  50. change(C[1], a[j].x, 1), size1 ++; j ++;
  51. }
  52. while(it0 <= n && query(C[0], it0) <= x) it0 ++; it0 --;
  53. while(it1 > 0 && query(C[1], it1) > x) it1 --;
  54. t = min(it0, it1);
  55. if(size0 - query(C[0], t) <= x && size1 - query(C[1], t) <= x) return 1;
  56. }
  57. return 0;
  58. }
  59.  
  60. int main(){
  61. n = read();
  62. 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;
  63. sort(li + 1, li + n + 1);
  64. tt = 0;
  65. li[0].first = -2147483647;
  66. for(int i = 1; i <= n; i ++){
  67. if(li[i].first != li[i - 1].first) tt ++;
  68. a[li[i].second].x = tt;
  69. }
  70. sort(a + 1, a + n + 1);
  71. int l = 1, r = n, ans = n;
  72. while(l <= r){
  73. int mid = (l + r) / 2;
  74. if(check(mid)) r = (ans = mid) - 1;
  75. else l = mid + 1;
  76. }
  77. printf("%d\n", ans);
  78. return 0;
  79. }

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 自定义状态码

    返回信息类(ResponseInfo): public class ResponseInfo { public static final String Status = "status&qu ...

  2. BZOJ4415: [Shoi2013]发牌

    显然可以线段树或树状数组上二分. 然而直接写splay在bzoj上并不会T. 然而发这题的目的只是因为我又忘了return了啊啊啊啊(TдT) 内心十分崩溃.关键是在本地还能过. #include&l ...

  3. css015 定位网页上的元素

    css015 定位网页上的元素 一.   定位属性的功能 1.         四中类型的定位 Position: absolute relative fixed static a. 绝对定位 绝对定 ...

  4. DataView

    表示用于排序.筛选.搜索.编辑和导航的 DataTable 的可绑定数据的自定义视图. DataView的功能类似于数据库的视图,他是数据源DataTable的封装对象,可以对数据源进行排序.搜索.过 ...

  5. easyUI draggable插件使用不当,导致拖动div内部文本框无法输入;设置echarts数据为空时就显示空白,不要动画和文字

    先上一个Demo <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://ww ...

  6. Java引用机制——reference

    所谓引用传递就是指将堆内存空间的使用权交给多个栈内存空间. 例子<1> public class Aliasing { int temp = 30; public static void ...

  7. Ajax与DOM实现动态加载

    阅读目录 DOM如何动态添加节点 Ajax异步请求 Chrome处理本地Ajax异步请求 参考: 首先说下问题背景:想要通过异步请求一个文本文件,然后通过该文件的内容动态创建一个DOM节点添加到网页中 ...

  8. Django笔记-常见错误整理

    1.csrf错误 解决方法:在settings.py里注释掉相关内容即可 MIDDLEWARE_CLASSES = ( 'django.contrib.sessions.middleware.Sess ...

  9. git命令之git tag 给当前分支打标签

    git tag - 标签相关操作 发表于 2011年06月29日 由 机器猫 标签可以针对某一时间点的版本做标记,常用于版本发布. 列出标签 $ git tag # 在控制台打印出当前仓库的所有标签$ ...

  10. AWK命令的用法

    1.awk命令简介: awk是一种可以处理数据.产生格式化报表的语言,功能十分强大. awk的工作方式是读取数据,将每一行数据视为一条记录(record)每笔记录以字段分隔符分成若干字段,然后输出各个 ...