L. Lifeguards(平面几何 点平分成两边)

https://www.jisuanke.com/contest/7190?view=challenges

题意:

给出n个点,你要找两个点AB,使得存在一半的点到A近,一半的点到B近,如果n是奇数,则可以存在至多一个点到两个点一样近。

解析:
你要找一条线平方两边的点,然后随便找两个点AB水平对称于这条线即可。
在这里插入图片描述
显然 A Y < B Y , A X < B X |AY|<|BY|,|AX|<|BX|

怎么找?我们可以先按照x轴排序,再按y轴排序。

在这里插入图片描述

奇数个点时,那条线穿过点 ( n + 1 ) / 2 (n+1)/2 ,斜率为-1e17。
偶数时,那条线穿过点 ( n + 1 ) / 2 (n+1)/2 向上移0.5距离,斜率为-1e17。

代码:

/*
 *  Author : Jk_Chen
 *    Date : 2020-03-14-14.21.38
 */
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define rep(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)
#define per(i,a,b) for(int i=(int)(a);i>=(int)(b);i--)
#define mmm(a,b) memset(a,b,sizeof(a))
#define pb push_back
#define pill pair<int, int>
#define fi first
#define se second
#define debug(x) cerr<<#x<<" = "<<x<<'\n'
const LL mod=1e9+7;
const int maxn=1e5+9;
const int inf=0x3f3f3f3f;
LL rd(){ LL ans=0; char last=' ',ch=getchar();
    while(!(ch>='0' && ch<='9'))last=ch,ch=getchar();
    while(ch>='0' && ch<='9')ans=ans*10+ch-'0',ch=getchar();
    if(last=='-')ans=-ans; return ans;
}
#define rd rd()
/*_________________________________________________________begin*/

pill p[maxn];

int main(){
    int n=rd;
    rep(i,1,n)p[i].fi=rd,p[i].se=rd;
    sort(p+1,p+1+n);
    if(n&1){
        printf("%lld %lld\n%lld %lld\n",1ll*p[n/2+1].fi+(LL)1e17,1ll*p[n/2+1].se+1,1ll*p[n/2+1].fi-(LL)1e17,1ll*p[n/2+1].se-1);
    }
    else{
        printf("%lld %lld\n%lld %lld\n",1ll*p[n/2].fi+(LL)1e17,1ll*p[n/2].se+1,1ll*p[n/2].fi-(LL)1e17,1ll*p[n/2].se);
    }

    return 0;
}

/*_________________________________________________________end*/
发布了773 篇原创文章 · 获赞 345 · 访问量 20万+

猜你喜欢

转载自blog.csdn.net/jk_chen_acmer/article/details/104875630