CSP 202009-1 称检测点查询 Java
程序员文章站
2022-04-27 11:03:20
import java.util.ArrayList;import java.util.Collections;import java.util.Scanner;class Coor implements Comparable { private int n; private double value; public Coor(int n, double value) { this.n = n; this.valu.....
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
class Coor implements Comparable<Coor> {
private int n;
private double value;
public Coor(int n, double value) {
this.n = n;
this.value = value;
}
public int getN() {
return n;
}
public void setN(int n) {
this.n = n;
}
public double getValue() {
return value;
}
public void setValue(double value) {
this.value = value;
}
@Override
public int compareTo(Coor o) {
if (this.value > o.value) return 1;
else if (this.value < o.value) return -1;
else return 0;
}
}
public class Main{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int n = input.nextInt();
int x = input.nextInt();
int y = input.nextInt();
ArrayList<Coor> dis = new ArrayList<Coor>();
for(int i=0;i<n;i++){
int tempX = input.nextInt();
int tempY = input.nextInt();
double distance = Math.sqrt((x-tempX)*(x-tempX)+(y-tempY)*(y-tempY));
dis.add(new Coor(i+1,distance));
}
Collections.sort(dis);
for(int i=0;i<3;i++){
System.out.println(dis.get(i).getN());
}
}
}
本文地址:https://blog.csdn.net/Mrwyx/article/details/110291150