BZOJ4411——[Usaco2016 Feb]Load balancing
#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的更多相关文章
- [bzoj4411] [Usaco2016 Feb]Load balancing
先离散化一下(也可以不用 枚举横坐标,用线段树维护两边纵坐标上的节点数. 每次在线段树上二分...(感觉似乎树状数组也行? #include<cstdio> #include<ios ...
- bzoj千题计划180:bzoj4411: [Usaco2016 Feb]Load balancing
http://www.lydsy.com/JudgeOnline/problem.php?id=4411 用树状数组维护扫描线 一个树状数组维护扫描线之上的y<=i点,另一个维护扫描线之下y&l ...
- BZOJ 4411: [Usaco2016 Feb]Load balancing 线段树+二分
code: #include <bits/stdc++.h> #define N 100060 #define M 1000000 #define lson x<<1 #def ...
- bzoj4409&&bzoj4410&&bzoj4411[Usaco2016 Feb Platinum]题解
辣鸡wyz最近状态奇差,于是想用usaco题找找手感,万万没想到被虐了一脸TAT 先贴代码,有空再填坑 4409[Usaco2016 Feb]Circular barn #include <io ...
- 【架构】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 ...
- 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 ...
- Codeforces Educational Codeforces Round 3 C. Load Balancing 贪心
C. Load Balancing 题目连接: http://www.codeforces.com/contest/609/problem/C Description In the school co ...
- UVA 12904 Load Balancing 暴力
Load Balancing Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/vi ...
- Load Balancing 折半枚举大法好啊
Load Balancing 给出每个学生的学分. 将学生按学分分成四组,使得sigma (sumi-n/4)最小. 算法: 折半枚举 #include <iostrea ...
随机推荐
- Eclipse导入项目:No projects are found to import
1 http://www.ztyhome.com/android-import-error/(网址不稳定详细内容如下:) 2如果发现导入工程(impot)的时候,出现”No projects are ...
- BigInteger类
当一个数字非常大时,则肯定无法使用基本类型接受,所以使用了BigInteger类. BigInteger类表示是大整数类,定义在java.math包中,如果在操作时一个整型数据已经超过了整数的最大类型 ...
- 《CSS3实战》读书笔记 第三章:选择器:样式实现的标记
第三章:选择器:样式实现的标记 选择器的魔力在于,让你完全实现对网页样式的掌控.不同的选择器可以用在不同的情况下使用.总之把握的原则是:规范的编码,根据合理地使用选择器,比去背选择器的定义有价值的多. ...
- ecshop后台,listtable.js使用
1.先载入listtable.js 2.html代码 a. <a href="javascript:listTable.sort('goods_number'); "> ...
- python 二分法查找实例(递归、循环)
二分法,主要应用于有序序列中,原理是每次查找都将原序列折半,逐渐缩小查找范围的一种算法. 需求 要求在一个有序序列中,例如[0, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30 ...
- C#异常类相关总结
C#异常类相关总结 C#异常类相关总结 C#异常类一.基类ExceptionC#异常类二.常见的异常类1.SystemException类:该类是System命名空间中所有其他异常类的基类.(建议:公 ...
- 彻底解决Eclipse自动补全变量名及变量名后面追加类型名
彻底解决Eclipse自动补全变量名问题的方法步骤 发布于 2014-11-04 14:53 已被阅读 31613159 次 大家使用eclipse或者MyEclipse敲代码的时候,是不是都被这 ...
- svn 回滚到某个版本
用svn merge命令来进行回滚. 回滚的操作过程如下: 1.保证我们拿到的是最新代码: svn update 假设最新版本号是28. 2.然后找出要回滚的确切版本号: svn log 假设根据sv ...
- tar命令的详细解释
tar命令的详细解释 标签: linuxfileoutputbashinputshell 2010-05-04 12:11 235881人阅读 评论(12) 收藏 举报 分类: linux/unix ...
- codeforces #270 ABCD
Codeforces Round #270 A - Design Tutorial: Learn from Math 题意:给出n,求出两个合数x和y使x+y=n. 题解:暴力筛合数,然后暴力找 // ...