#include<bits/stdc++.h> using namespace std; struct pos{ int x; int y; }; bool cmp(pos& p1, pos& p2) { if (p1.y < p2.y) return true; else if (p1.y == p2.y) return p1.x < p2.x; else return false; } int main() { // ios::sync_with_stdio(0); int n, X, Y; cin>>n>>X>>Y; struct pos ps[n + 1]; //记录数值 struct pos dis[n + 1]; //记录i和距离 for (int i = 1; i <= n; i++) { cin>>ps[i].x>>ps[i].y; } for (int i = 1; i <= n; i++) { int x = ps[i].x; int y = ps[i].y; int place = (x - X)*(x - X) + (y - Y)*(y - Y); dis[i].x = i; dis[i].y = place;//juli } sort(dis + 1,dis + 1 + n, cmp); for (int i = 1; i <= 3; i++) { cout<<dis[i].x<<endl; } return 0; }
原文:https://www.cnblogs.com/Kkvass/p/14640713.html