题目
题解
这道sb模拟都写不出来,还搞什么线段树,枚举切的边就可以过
代码
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;
const int maxn=1e6+100;
const int inf=1e9;
int read(){
char ch=getchar(); int now=0,f=1;
while (ch<'0' || ch>'9') {
if (ch=='-') f=-1; ch=getchar();}
while (ch>='0'&&ch<='9') {now=(now<<1)+(now<<3)+ch-'0'; ch=getchar();}
return now*f;}
struct Cow{
int x,y;
}a[maxn],b[maxn];
int n,top,ans=inf,head[maxn];
bool cmpx(Cow x,Cow y) {
return x.x<y.x;}
bool cmpy(Cow x,Cow y) {
return x.y<y.y;}
void work(int k)//k是竖线
{
int l=0,r=0,L=0,R=0,now=1;
for (int i=1; i<=n; i++) if (a[i].x<k) L++;
R=n-L;
for (int i=1; i<=top; i++)
{
int kk=head[i]+1;
while (now<=n && b[now].y<=kk)
{
if (b[now].x<k) l++; else r++;
now++;
}
// printf("%d %d\n",l,r);
ans=min(ans,max(max(l,L-l),max(r,R-r)));
}
// printf("%d\n",ans);
}
int main()
{
n=read();
for (int i=1; i<=n; i++)
{
a[i].x=read(); a[i].y=read(); b[i]=a[i];
}
sort(a+1,a+1+n,cmpx);
sort(b+1,b+1+n,cmpy);
for (int i=1; i<=n; i++) if (b[i].y!=head[top]) head[++top]=b[i].y;//标记有牛出现的行
// for (int i=1; i<=top; i++) printf("%d ",head[i]);
for (int i=1; i<=n; i++)
if (a[i].x!=a[i-1].x) work(a[i].x+1);
printf("%d\n",ans);
return 0;
}