模拟——洛谷P3138 [USACO16FEB]负载平衡Load Balancing

https://www.luogu.org/problem/show?pid=3138
这一题你做一点预处理,然后直接枚举两条切线就好了;
很简单的一个离散;
好像也不算说明离散;

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
using namespace std;
struct cs{
    int x,y;
}a[1005],b[1005];
int c[1005],top;
int L,R,l,r,o;
int n,m,ans;
bool cmp(cs a,cs b){return a.x<b.x;}
bool cmp2(cs a,cs b){return a.y<b.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;//统计切线分成的两半的点数 
    o=1;
    for(int i=1;i<=top;i++){
        int kk=c[i]+1;//枚举切线 
        for(;o<=n&&b[o].y<=kk;++o)
            if(b[o].x<k)++L;else ++R;//统计点数 
        ans=min(ans,max(max(L,l-L),max(R,r-R)));//更新答案; 
    }   
}
int main()
{
    ans=1e9;
    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,cmp);//按x递增排序 
    sort(b+1,b+n+1,cmp2);//按y 
    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);
}

转载于:https://www.cnblogs.com/largecube233/p/6797856.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值