You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
# include <bits/stdc++.h>
using namespace std ;
const int N = 100010 ;
int n ;
int a1 , b1 , a2 , b2 ;
struct Point {
int x , y ;
int d ;
bool operator < ( const Point & W ) const {
return d < W . d ;
}
} point [ N ] ;
// 利用欧几里得距离,计算两点间的距离平方,也就是半径的平方
int get_dist ( int x1 , int y1 , int x2 , int y2 ) {
int dx = x1 - x2 ;
int dy = y1 - y2 ;
return dx * dx + dy * dy ;
}
int main ( ) {
scanf ( " %d%d%d%d " , & a1 , & b1 , & a2 , & b2 ) ;
scanf ( " %d " , & n ) ;
for ( int i = 0 ; i < n ; i + + ) {
int x , y ;
scanf ( " %d%d " , & x , & y ) ;
point [ i ] = { x , y , get_dist ( x , y , a1 , b1 ) } ; // 计算每个导弹到A1拦截系统的距离
}
// 按距离由大到小排序
sort ( point , point + n ) ;
reverse ( point , point + n ) ;
int res = point [ 0 ] . d , r = 0 ; // res初始化为离A1拦截系统最远的导弹距离,r是A2拦截系统的半径, 因为如果最远的都归A1系统拦截, 那么A2什么也不用拦截, 半径为0
for ( int i = 0 ; i < n ; i + + ) { // 枚举每个导弹
r = max ( r , get_dist ( point [ i ] . x , point [ i ] . y , a2 , b2 ) ) ; // 更新与A2拦截系统的距离,也就是A2系统的半径
res = min ( res , point [ i + 1 ] . d + r ) ; // 由于是按距离A1拦截系统由大到小排序, 所以, point[i+1]意味着把[0~i]的给A2拦截, [i+1,n-1]归A1拦截
}
// 注意: 这里面i=n-1时, point[i+1].d=point[n-1+1].d=point[n].d, 此时point[n].d是0,
// point[i + 1].d + r=r,这时的真实场景是把所有导弹都让A2拦截系统拦截, A1一个也不拦截
// 输出答案
printf ( " %d \n " , res ) ;
return 0 ;
}