思路:用结构体存起来每个点和(X,Y)的距离平方和(不需要开根号 防止精度丢失)以及当前点的id,排序一下即可。
#include<bits/stdc++.h>
using namespace std
;
const int N
=205;
struct node
{
int dis
,id
;
}a
[N
];
bool
cmp(node a
,node b
){
if(a
.dis
==b
.dis
) return a
.id
<b
.id
;
return a
.dis
<b
.dis
;
}
int main(){
int n
,X
,Y
;cin
>>n
>>X
>>Y
;
for(int i
=1;i
<=n
;i
++){
int x
,y
;cin
>>x
>>y
;
a
[i
].dis
=(x
-X
)*(x
-X
)+(y
-Y
)*(y
-Y
);
a
[i
].id
=i
;
}
sort(a
+1,a
+n
+1,cmp
);
for(int i
=1;i
<=3;i
++) cout
<<a
[i
].id
<<endl
;
return 0;
}
转载请注明原文地址: https://lol.8miu.com/read-37832.html