CSP-202009-1-称检测点查询
解题代码
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct MyDistance
{
long long index, distance;
};
bool cmp(MyDistance& a, MyDistance& b) {
if (a.distance == b.distance) return a.index < b.index;
return a.distance < b.distance;
}
long long n, X, Y, x, y;
int main() {
cin >> n >> X >> Y;
vector<MyDistance>list(n);
for (size_t i = 0; i < n; i++)
{
cin >> x >> y;
list[i].index = i + 1;
list[i].distance = (x - X) * (x - X) + (y - Y) * (y - Y);
}
sort(list.begin(), list.end(), cmp);
for (size_t i = 0; i < 3; i++)
{
cout << list[i].index << endl;
}
return 0;
}