202009-1 称检测点查询
要从一堆点中,找出距离 ( x , y ) (x,y) (x,y)最近的3个点,直接定义一下排序规则,排序后输出前3个点的编号即可
#include <stdio.h>
#include <iostream>
#include <queue>
#include <map>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long ll;
void pt(){ cout<<'\n';}
template<class H, class ... T> void pt(H h,T... t){ cout<<" "<<h; pt(t...);}
const ll maxn = 1e6+10;
ll N,X,Y;
struct node{
ll x,y,id;
bool operator <(const node &o) const{
ll d1 = (X - x)*(X - x) + (Y-y)*(Y-y);
ll d2 = (X - o.x)*(X - o.x) + (Y-o.y)*(Y-o.y);
if(d1 != d2) return d1 < d2;
else return id < o.id;
}
}p[maxn];
int main(){
cin>>N>>X>>Y;
for(int i = 1;i<=N;i++) {
scanf("%lld %lld",&p[i].x,&p[i].y);
p[i].id = i;
}
sort(p+1,p+N+1);
for(int i = 1;i<=3;i++){
printf("%lld\n",p[i].id);
}
return 0;
}