#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
struct place{
int x,y;
};
struct city{
int x,y;
int da,db;
};
int d(city a,place b){
return pow((a.x-b.x),2)+pow((a.y-b.y),2);
}
bool cmp(city a,city b){
return (min(a.da,a.db)>min(b.da,b.db))||(min(a.da,a.db)==min(b.da,b.db)&&max(a.da,a.db)>max(b.da,b.db));
}
city c[1000000];
signed main(){
ios::sync_with_stdio(0),cin.tie(0);
place a,b;
cin>>a.x>>a.y>>b.x>>b.y;
int n;cin>>n;
for(int i=0;i<n;i++){
cin>>c[i].x>>c[i].y;
c[i].da=d(c[i],a),c[i].db=d(c[i],b);
}
sort(c,c+n,cmp);
int ra=0,rb=0;
for(int i=0;i<n;i++){
if(ra<c[i].da&&rb<c[i].db){
if(rb+c[i].da>ra+c[i].db)rb=c[i].db;
else if(rb+c[i].da<ra+c[i].db)ra=c[i].da;
else{
if(c[i].da>c[i].db)ra=c[i].da;
else rb=c[i].db;
}
}
}
cout<<ra+rb<<endl;
}
//owo
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
struct place{
int x,y;
};
struct city{
int x,y;
int da,db;
};
int d(city a,place b){
return pow((a.x-b.x),2)+pow((a.y-b.y),2);
}
bool cmp(city a,city b){
return (min(a.da,a.db)>min(b.da,b.db))||(min(a.da,a.db)==min(b.da,b.db)&&max(a.da,a.db)>max(b.da,b.db));
}
city c[1000000];
signed main(){
ios::sync_with_stdio(0),cin.tie(0);
place a,b;
cin>>a.x>>a.y>>b.x>>b.y;
int n;cin>>n;
for(int i=0;i<n;i++){
cin>>c[i].x>>c[i].y;
c[i].da=d(c[i],a),c[i].db=d(c[i],b);
}
sort(c,c+n,cmp);
int ra=0,rb=0;
for(int i=0;i<n;i++){
if(ra<c[i].da&&rb<c[i].db){
if(rb+c[i].da>ra+c[i].db)rb=c[i].db;
else if(rb+c[i].da<ra+c[i].db)ra=c[i].da;
else{
if(c[i].da>c[i].db)ra=c[i].da;
else rb=c[i].db;
}
}
}
cout<<ra+rb<<endl;
}
//owo
可以解釋一下你的思路嗎 你寫得有點亂
PS 學長好電 20分鐘AC 嗚嗚嗚我好爛