传送门
题意:目标就是找到 n 个点中离 (X,Y)直线距离最近的情况下编号最小的三个点,直接记录每个点与 (X,Y)的距离再结构体排序一下就好啦。
代码实现:
import java.util.*;class node implements Comparable<node>{int id, da;public node(int id, int da){this.id = id;this.da = da;}@Overridepublic int compareTo(node o) {if(this.da!=o.da)return this.da-o.da;elsereturn this.id-o.id;}
}public class Main {public static void main(String[] args) {Scanner in = new Scanner(System.in);int n = in.nextInt();int x = in.nextInt();int y = in.nextInt();node [] a = new node[250];for(int i = 1; i <= n; i ++){int u = in.nextInt();int v = in.nextInt();a[i] = new node(i, (u-x)*(u-x)+(v-y)*(v-y));}Arrays.sort(a, 1, n+1);for(int i = 1; i <= 3; i ++)System.out.println(a[i].id);in.close();}
}