洛谷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 负载平衡入门篇
一.简单介绍负载均衡 负载均衡也称负载共享,它是指负载均衡是指通过对系统负载情况进行动态调整,把负荷分摊到多个操作节点上执行,以减少系统中因各个节点负载不均衡所造成的影响,从而提高系统的工作效率.在常 ...
随机推荐
- 命令行执行大sql文件
mysql -h localhost -u root -p 123456 < F:/hello world/niuzi.sql
- C# 多线程 线程池(ThreadPool) 2 如何控制线程池?
线程池启动了,但是没有方法去控制线程池,如果子线程出现了问题,难道线程池就死了吗? 我们可以设置线程池的线程数量,进行加入任务,线程池会自动分配并且合理的执行,但是控制不了又有啥意思呢. 线程池里线程 ...
- SPOJ375Query on a tree I(树剖+线段树)(询问边)
ιYou are given a tree (an acyclic undirected connected graph) with N nodes, and edges numbered 1, 2, ...
- px-rem自适应转换(进阶@rem:40rem; )
接力之前的文章 https://www.cnblogs.com/leshao/p/5674710.html 这篇文章讲解的是px -rem 单位换算 除100的 写法 比如实际测量PSD宽度是500 ...
- 数据schemaAvro简介
文章结束给大家来个程序员笑话:[M] 最近在研究Thrift和Avro以及它们的区分,通过各种渠道搜集资料,现整顿出有关Avro的一些资料,方便当前参考. 一.弁言 1. 简介 Avro是Hadoop ...
- java.util Properties使用记录
转:http://www.2cto.com/px/201006/47834.html 在java.util 包下面有一个类 Properties,该类主要用于读取以项目的配置文件(以.properti ...
- HDOJ1495(倒水BFS)
非常可乐 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- JVM插码之三:javaagent介绍及javassist介绍
本文介绍一下,当下比较基础但是使用场景却很多的一种技术,稍微偏底层点,就是字节码插庄技术了...,如果之前大家熟悉了asm,cglib以及javassit等技术,那么下面说的就很简单了...,因为下面 ...
- 一个能获取如果hash或search是中文的内容小例子
代码: (function () { var url = "http//baidu.com#a=你好&b=world"; var url1 = "http//ba ...
- altium designer 中的top/bottom solder和top/bottom paste mask
转载请注明出处:http://blog.csdn.net/qq_26093511/article/details/51751936 1.top solder为助焊层,说白一点就是说,有这个层的地方就没 ...