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