洛谷P3138 [USACO16FEB]负载平衡Load Balancing_Silver
2017-10-23 15:32
239 查看
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=0; for(int i=1;i<=n;i++){ if(a[i].x<k)l++; else r++; } now=1; for(int i=1;i<=top;i++){ int kk=c[i]+1; 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=1;i<=n;i++)scanf("%d%d",&a[i].x,&a[i].y),b[i]=a[i]; sort(a+1,a+n+1,cmp1); sort(b+1,b+n+1,cmp2); for(int i=1;i<=n;i++)if(b[i].y!=c[top])c[++top]=b[i].y; for(int i=1;i<=n;i++)cfb(a[i].x+1); printf("%d",ans); }
相关文章推荐
- 模拟——洛谷P3138 [USACO16FEB]负载平衡Load Balancing
- bzoj 4411 USACO16FEB 负载平衡Load Balancing(扫描线,树状数组,三分答案,前缀和)
- USACO 2016 February Contest, Silver Problem 2. Load Balancing
- USACO 2014 Dec Silver 1.Piggyback 题解
- POJ P3264 USACO 2007 洛谷 P2880 January Silver Balanced Lineup【线段树】
- 【USACO FEB 2010 SILVER】吃巧克力(Chocolate Eating)
- USACO2014FebruarySilver Secret Code
- cqbzoj2402【USACO FEB 2010 SILVER】吃巧克力
- USACO 2009 Open Silver 3.Cow Digit Game简单博弈论
- BZOJ - 1609/USACO - Feb08 Silver Eating Together 麻烦的聚餐 重庆一中高2018级竞赛班第九次测试 2016.9.10 Problem 2
- bzoj千题计划180:bzoj4411: [Usaco2016 Feb]Load balancing
- USACO 2008 Open Silver-Cow Cars
- 【USACO 2008 January Silver】架设电话线 二分答案+最短路
- USACO 2015 US OPEN CONTEST,Silver Division Solution
- usaco silver刷水~其实是回顾一下,补题解
- USACO 2010 Open Silver 3.Time Travel 链表?
- Cpp环境【POJ2435】【CQYZOJ3034】【USACO2005 U S Open Silver】Navigating the City城市交通
- [USACO16OPEN]关闭农场Closing the Farm_Silver
- USACO2014Open Silver Odometer
- 【Usaco 2007 Dec silver】穿越泥地 (Standard IO)