洛谷P3138 [USACO16FEB]负载平衡Load Balancing_Silver
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.
输入输出样例
7
7 3
5 5
7 13
3 1
11 7
5 3
9 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的更多相关文章
- 【洛谷 P4016】 负载平衡问题(费用流)
题目链接 环形均分纸牌,既然是网络流23题的那就用网络流做把. 套路拆点. 供需平衡. 源点向大于平均数的点的入点连流量为这个数减去平均数的差,费用为0的边,表示需要移走这么多. 小于平均数的点的出点 ...
- 【洛谷】P2880 [USACO07JAN]平衡的阵容Balanced Lineup(st表)
题目背景 题目描述: 每天,农夫 John 的N(1 <= N <= 50,000)头牛总是按同一序列排队. 有一天, John 决定让一些牛们玩一场飞盘比赛. 他准备找一群在对列中为置连 ...
- 洛谷 P3137 [USACO16FEB]圆形谷仓Circular Barn_Silver
P3137 [USACO16FEB]圆形谷仓Circular Barn_Silver 题目描述 Being a fan of contemporary architecture, Farmer Joh ...
- 洛谷 P4016负载平衡问题【费用流】题解+AC代码
洛谷 P4016负载平衡问题 P4014 分配问题[费用流]题解+AC代码 负载平衡问题 题目描述 GG 公司有n个沿铁路运输线环形排列的仓库,每个仓库存储的货物数量不等.如何用最少搬运量可以使 n ...
- 洛谷P4016负载平衡
题目 负载平衡问题是一个比较经典的网络流问题,但是该问题还有一个数学贪心法. 所以做这个题前,其实可以做一下均分纸牌问题. 均分纸牌问题 均分纸牌问题可以说是作为贪心的入门题. 做法 首先我们应当把原 ...
- (洛谷P2512||bzoj1045) [HAOI2008]糖果传递 || 洛谷P4016 负载平衡问题 || UVA11300 Spreading the Wealth || (洛谷P3156||bzoj3293) [CQOI2011]分金币
bzoj1045 洛谷P4016 洛谷P2512 bzoj3293 洛谷P3156 题解:https://www.luogu.org/blog/LittleRewriter/solution-p251 ...
- 洛谷 P6783 - [Ynoi2008] rrusq(KDT+势能均摊+根号平衡)
洛谷题面传送门 首先显然原问题严格强于区间数颜色,因此考虑将询问离线下来然后用某些根号级别复杂度的数据结构.按照数颜色题目的套路,我们肯定要对于每种颜色维护一个前驱 \(pre\),那么答案可写作 \ ...
- 洛谷 P4240 - 毒瘤之神的考验(数论+复杂度平衡)
洛谷题面传送门 先扯些别的. 2021 年 7 月的某一天,我和 ycx 对话: tzc:你做过哪些名字里带"毒瘤"的题目,我做过一道名副其实的毒瘤题就叫毒瘤,是个虚树+dp yc ...
- Windows Server 2008 R2 负载平衡入门篇
一.简单介绍负载均衡 负载均衡也称负载共享,它是指负载均衡是指通过对系统负载情况进行动态调整,把负荷分摊到多个操作节点上执行,以减少系统中因各个节点负载不均衡所造成的影响,从而提高系统的工作效率.在常 ...
随机推荐
- cin.get(),cin.getline(),getline(),gets(),getchar()
1.cin.get() (1).cin.get()-------提取单个字符,可以提取回车.空格 a=cin.get(); (2) 同(1)---------------提取单个字符,可以提取回车.空 ...
- 再次理解WCF以及其通信(附加一個編程小經驗)
一.概述 Windows Communication Foundation(WCF)是由微软发展的一组数据通信的应用程序开发接口,可以翻译为Windows通讯接口,它是.NET框架的一部分.由 .NE ...
- html网页小图标
<link rel="shortcut icon" href="../image/favicon.ico"/>
- visual studio tools for unity代码提示快捷键
visual studio tools for unity代码提示快捷键 ctrl+ shift +q
- 【leetcode刷题笔记】ZigZag Conversion
The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like ...
- bzoj3595 方伯伯的oj
有$n$个数,一开始是$1~n$,有$m$次操作 1.把编号为$x$的人编号改为$y$,保证$y$没出现过 2.把编号为$x$的人提到第一名 3.把编号为$x$的人怼到最后一名 4.查询排名为$x$的 ...
- ACM学习历程—HDU5476 Explore Track of Point(平面几何)(2015上海网赛09题)
Problem Description In Geometry, the problem of track is very interesting. Because in some cases, th ...
- Python xlrd、xlwt、xlutils修改Excel文件-OK
一.xlrd读取excel 这里介绍一个不错的包xlrs,可以工作在任何平台.这也就意味着你可以在Linux下读取Excel文件. 首先,打开workbook: import xlrdwb = ...
- Excel用vlookup方法匹配数据
(1) VLOOKUP是一个查找函数,给定一个查找的目标,它就能从指定的查找区域中查找返回想要查找到的值.它的基本语法为: VLOOKUP(查找目标,查找范围,返回值的列数,精确OR模糊查找) ...
- css3 tranform perspective属性
perspective 属性用于规定观察点距离元素的距离, 1 观察点距离元素越近,元素变形就越大,灭点距离越近. 2 观察点距离元素越远,元素变形越小,灭点距离也就越远. 比如设置perspecti ...