导弹拦截 牛客

https://ac.nowcoder.com/acm/problem/16601

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<set>
#include<queue>
#include<cmath>
using namespace std;
typedef long long ll;
/*
1、为什么要求是系统2最大值于系统1当前的那颗导弹求最小
    因为最大值就说明系统二可以覆盖所有的点
    
通过第二个系统来为第一个(总)系统减轻负担
*/
struct node{
    ll x,y;
    ll d1,d2;
};
node b[100005];
ll x1,y11,x2,y2,n;


bool cmp(node a,node b){
   return a.d1>b.d1;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>x1>>y11>>x2>>y2;
    cin>>n;
    node a;
    ll cnt1 = 1,cnt2 = 1;
    for(int i = 1; i <= n; i++){
        cin>>b[i].x>>b[i].y;
        b[i].d1 = (b[i].x - x1)*(b[i].x - x1) + (b[i].y-y11)*(b[i].y-y11);
        b[i].d2 = (b[i].x - x2)*(b[i].x - x2) + (b[i].y-y2)*(b[i].y-y2);
    }
    sort(b+1,b+n+1,cmp);
    ll ma = b[1].d2;
    ll ans = b[1].d1;
    for(int i = 2; i <= n+1; i++){
        ma = max(ma,b[i-1].d2);
        ans = min(ans,ma+b[i].d1);
        //cout<<ans<<endl;
    }
    cout<<ans<<endl;
    return 0;
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值