方法暴力了点,但是主要就是学个语法。
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <string>
#include <cstring>
#include <math.h>
using namespace std;
const int INF = 0x3f3f3f3f;
// id, dis
bool cmp (pair<int, int> a, pair<int, int> b) {
if (a.second == b.second) {
return a.first < b.first;
} else {
return a.second < b.second;
}
}
int main() {
int n, x, y;
int x_p, y_p;
vector<pair<int, int>> points;
cin >> n >> x >> y;
for (int i = 0; i < n; i++) {
cin >> x_p >> y_p;
int d = pow(x-x_p, 2) + pow(y-y_p, 2);
auto pair = make_pair(i, d);
points.push_back(pair);
}
sort(points.begin(), points.end(), cmp);
for (int i =0; i<3; i++) {
cout << points[i].first+1 << endl;
}
return 0;
}