P3138 [USACO16FEB]负载平衡Load Balancing_Silver

题目描述

Farmer John's NN cows are each standing at distinct locations (x_1, y_1) \ldots (x_n, y_n)(x1​,y1​)…(xn​,yn​) on his two-dimensional farm (1 \leq N \leq 10001≤N≤1000, and the x_ixi​'s and y_iyi​'s are positive odd integers of size at most 1,000,0001,000,000). FJ wants to partition his field by building a long (effectively infinite-length) north-south fence with equation x=ax=a (aa will be an even integer, thus ensuring that he does not build the fence through the position of any cow). He also wants to build a long (effectively infinite-length) east-west fence with equation y=by=b, where bb is an even integer. These two fences cross at the point (a,b)(a,b), and together they partition his field into four regions.

FJ wants to choose aa and bb so that the cows appearing in the four resulting regions are reasonably "balanced", with no region containing too many cows. Letting MM be the maximum number of cows appearing in one of the four regions, FJ wants to make MM as small as possible. Please help him determine this

smallest possible value for MM.

给你一个矩阵,里面有些点,让你横向切一刀,纵向切一刀,使得得到的四个区域内的最大的点数最少。

输入输出格式

输入格式:

The first line of the input contains a single integer, NN. The next NN lines

each contain the location of a single cow, specifying its xx and yy

coordinates.

输出格式:

You should output the smallest possible value of MM that FJ can achieve by

positioning his fences optimally.

输入输出样例

输入样例#1: 复制

7
7 3
5 5
7 13
3 1
11 7
5 3
9 1
输出样例#1: 复制

2
/*
预处理+枚举两条切线
*/
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#define maxn 1005
using namespace std;
struct node{
int x,y;
}a[maxn],b[maxn];
int c[maxn],top,L,R,l,r,now;
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 cfb(int k){
l=r=L=R=;
for(int i=;i<=n;i++){
if(a[i].x<k)l++;
else r++;
}
now=;
for(int i=;i<=top;i++){
int kk=c[i]+;
for(;now<=n&&b[now].y<=kk;now++){
if(b[now].x<k)L++;
else R++;
}
ans=min(ans,max(max(L,l-L),max(R,r-R)));
}
}
int main(){
scanf("%d",&n);
for(int i=;i<=n;i++)scanf("%d%d",&a[i].x,&a[i].y),b[i]=a[i];
sort(a+,a+n+,cmp1);
sort(b+,b+n+,cmp2);
for(int i=;i<=n;i++)if(b[i].y!=c[top])c[++top]=b[i].y;
for(int i=;i<=n;i++)cfb(a[i].x+);
printf("%d",ans);
}

洛谷P3138 [USACO16FEB]负载平衡Load Balancing_Silver的更多相关文章

  1. 【洛谷 P4016】 负载平衡问题(费用流)

    题目链接 环形均分纸牌,既然是网络流23题的那就用网络流做把. 套路拆点. 供需平衡. 源点向大于平均数的点的入点连流量为这个数减去平均数的差,费用为0的边,表示需要移走这么多. 小于平均数的点的出点 ...

  2. 【洛谷】P2880 [USACO07JAN]平衡的阵容Balanced Lineup(st表)

    题目背景 题目描述: 每天,农夫 John 的N(1 <= N <= 50,000)头牛总是按同一序列排队. 有一天, John 决定让一些牛们玩一场飞盘比赛. 他准备找一群在对列中为置连 ...

  3. 洛谷 P3137 [USACO16FEB]圆形谷仓Circular Barn_Silver

    P3137 [USACO16FEB]圆形谷仓Circular Barn_Silver 题目描述 Being a fan of contemporary architecture, Farmer Joh ...

  4. 洛谷 P4016负载平衡问题【费用流】题解+AC代码

    洛谷 P4016负载平衡问题 P4014 分配问题[费用流]题解+AC代码 负载平衡问题 题目描述 GG 公司有n个沿铁路运输线环形排列的仓库,每个仓库存储的货物数量不等.如何用最少搬运量可以使 n ...

  5. 洛谷P4016负载平衡

    题目 负载平衡问题是一个比较经典的网络流问题,但是该问题还有一个数学贪心法. 所以做这个题前,其实可以做一下均分纸牌问题. 均分纸牌问题 均分纸牌问题可以说是作为贪心的入门题. 做法 首先我们应当把原 ...

  6. (洛谷P2512||bzoj1045) [HAOI2008]糖果传递 || 洛谷P4016 负载平衡问题 || UVA11300 Spreading the Wealth || (洛谷P3156||bzoj3293) [CQOI2011]分金币

    bzoj1045 洛谷P4016 洛谷P2512 bzoj3293 洛谷P3156 题解:https://www.luogu.org/blog/LittleRewriter/solution-p251 ...

  7. 洛谷 P6783 - [Ynoi2008] rrusq(KDT+势能均摊+根号平衡)

    洛谷题面传送门 首先显然原问题严格强于区间数颜色,因此考虑将询问离线下来然后用某些根号级别复杂度的数据结构.按照数颜色题目的套路,我们肯定要对于每种颜色维护一个前驱 \(pre\),那么答案可写作 \ ...

  8. 洛谷 P4240 - 毒瘤之神的考验(数论+复杂度平衡)

    洛谷题面传送门 先扯些别的. 2021 年 7 月的某一天,我和 ycx 对话: tzc:你做过哪些名字里带"毒瘤"的题目,我做过一道名副其实的毒瘤题就叫毒瘤,是个虚树+dp yc ...

  9. Windows Server 2008 R2 负载平衡入门篇

    一.简单介绍负载均衡 负载均衡也称负载共享,它是指负载均衡是指通过对系统负载情况进行动态调整,把负荷分摊到多个操作节点上执行,以减少系统中因各个节点负载不均衡所造成的影响,从而提高系统的工作效率.在常 ...

随机推荐

  1. Java_异常_06_ Unsupported major.minor version 52.0

    二.参考资料 1.如何解决Unsupported major.minor version 52.0问题? 2.Unsupported major.minor version 52.0 3. Unsup ...

  2. Web视频播放 之 【HTML5 Video标签】

    一.说明 HTML5中引入了video标签用于方便的在浏览器中播放视频,不在需要对flashPlayer进行依赖,更加轻量级.但在浏览器兼容.视频协议支持方面还有一些需要注意的问题. 二.浏览器兼容 ...

  3. [SHOI2017]期末考试

    题目描述 有n位同学,每位同学都参加了全部的m门课程的期末考试,都在焦急的等待成绩的公布. 第i位同学希望在第ti天或之前得知所有课程的成绩.如果在第ti天,有至少一门课程的成绩没有公布,他就会等待最 ...

  4. bzoj1014火星人

    ...强迫症终于A了这道题  bzoj前30道全A指日可待 splay维护这个结点控制的字符串的hash值 每次旋转重新算一遍就可以了 查询的时候跑一个二分 讲起来很简单但是还是调了1h才调对了spl ...

  5. ACM学习历程—HDU1695 GCD(容斥原理 || 莫比乌斯)

    Description Given 5 integers: a, b, c, d, k, you're to find x in a...b, y in c...d that GCD(x, y) = ...

  6. 分立元件封装尺寸及PCB板材工艺与设计实例

    分立元件封装尺寸 inch mm (L)mm (w)mm (t)mm (a)mm (b)mm 0201 0603 0.6±0.05 0.30±0.05 0.23±0.05 0.10±0.05 0.60 ...

  7. Bootstrap CSS教程

    Bootstrap 教程 Bootstrap,来自 Twitter,是目前最受欢迎的前端框架.Bootstrap 是基于 HTML.CSS.JAVASCRIPT 的,它简洁灵活,使得 Web 开发更加 ...

  8. jraiser小结

    1 合并小结 jrcpl F:\site\js\app --settings package.settings 上面代码的意思,就是说,根据package.settings文件,来对app文件夹下的所 ...

  9. bzoj 2395 Timeismoney —— 最小乘积生成树

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2395 参考博客:https://www.cnblogs.com/autsky-jadek/p ...

  10. Windows Touch 便笺簿的

    Windows Touch 便笺簿的 C# 示例 (MTScratchpadWMTouchCS)   本节介绍 Windows Touch 便笺簿的 C# 示例. Windows Touch 便笺簿的 ...