这道题非常的……简单,呃:
首先:
struct node{
int x,y,n;
}a[100010];
int dis(int x1,int y1,int x2,int y2){
return (x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
}
bool cmp(node x,node y){
return x.n>y.n;
}
然后:
int ax,ay,bx,by,n,r,temp,ans,ra,rb;
int main(){
cin>>ax>>ay>>bx>>by>>n;
for(int i=1;i<=n;i++){
cin>>a[i].x>>a[i].y;
a[i].n=dis(a[i].x,a[i].y,ax,ay);
}
sort(a+1,a+n+1,cmp);
ra=a[1].n;
ans=ra;
rb=0;
for(int i=2;i<=n+1;i++){
ra=a[i].n;
temp=dis(a[i-1].x,a[i-1].y,bx,by);
rb=max(temp,rb);
ans=min(ans,ra+rb);
}
cout<<ans;
return 0;
}
就AC了,附上完整代码:
#include <iostream>
#include <cstdio>
#include <bits/stdc++.h>
using namespace std;
struct node{
int x,y,n;
}a[100010];
int dis(int x1,int y1,int x2,int y2){
return (x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
}
bool cmp(node x,node y){
return x.n>y.n;
}
int ax,ay,bx,by,n,r,temp,ans,ra,rb;
int main(){
cin>>ax>>ay>>bx>>by>>n;
for(int i=1;i<=n;i++){
cin>>a[i].x>>a[i].y;
a[i].n=dis(a[i].x,a[i].y,ax,ay);
}
sort(a+1,a+n+1,cmp);
ra=a[1].n;
ans=ra;
rb=0;
for(int i=2;i<=n+1;i++){
ra=a[i].n;
temp=dis(a[i-1].x,a[i-1].y,bx,by);
rb=max(temp,rb);
ans=min(ans,ra+rb);
}
cout<<ans;
return 0;
}