洛谷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 负载平衡入门篇
一.简单介绍负载均衡 负载均衡也称负载共享,它是指负载均衡是指通过对系统负载情况进行动态调整,把负荷分摊到多个操作节点上执行,以减少系统中因各个节点负载不均衡所造成的影响,从而提高系统的工作效率.在常 ...
随机推荐
- Runtime Error(ACCESS_VIOLATION)
1. while(scanf("%d",&n) )// 错误,会出现 Runtime Error(ACCESS_VIOLATION) while(scanf(&q ...
- JS常用工具类代码
http://www.cnblogs.com/liszt/archive/2011/08/16/2140007.html js/javascript删除字符串中的html标签 function rem ...
- 一些有意思的面试题(持续更新) .C语言编程技巧札记
一些有意思的面试题(持续更新) http://blog.csdn.net/wangyuling1234567890/article/details/38565239 C语言编程技巧札记 http:// ...
- WampServer 2.5设置外网访问/局域网手机访问(403 Forbidden错误解决方法)
安装好wamp后,想用手机通过局域访问电脑上wamp下的网页,结果出现如下提示. (403 Forbidden)错误 1.打开http.conf文件 2.找到下图中红色方框中的onlineofflin ...
- node.js 安装及配置(hello world)及 node 的包管理器(npm)
下载地址:Download | Node.js,无脑下一步安装即可: 安装时,会自动将 node 可执行文件路径添加进 Path 内,这样进入 cmd 命令行,以查看 node 的安装版本: > ...
- 配置 VS Code 调试 PHP
配置 VS Code 调试 PHP 1.下载 xampp 集成服务器wampserver3.1.0-Apache2.4.7_PHP5.6.3-7.0.23-7.1.19_MySQL5.7.19_Mar ...
- 如何使用ODB(How to use odb On windows)
1.下载ODB library:ODB Compiler,Common Runtime Library,Database Runtime Library. http://www.codesynthes ...
- glusterfs安装配置简单使用
GlusterFS是一种分布式分布式文件系统,默认采用无中心完全对等架构,搭建维护使用十分简单,是很受欢迎的分布式文件系统. 官网https://www.gluster.org/,官网上表示Glust ...
- 《Kubernetes权威指南第2版》学习(四)kubernetes基本概念和术语
1: etcd是干什么的: 键-值存储仓库,用来配置共享和服务发现. k8s把Node, pod,replication controller, Services看做是资源对象,这些资源对象可以通过K ...
- 弱网测试--使用fiddle进行弱网测试
数据源于:http://blog.csdn.net/eleven521/article/details/19089671 弱网测试原理以及方法(一)一.为什么要进行弱网测试?按照移动特性,各种网络连接 ...