public class ClosestPair{
public static void main(String[] args) {
float[][] a = new float[][]{{3, 3}, {1, 5}, {4, 6}, {2, 8}, {9, 9},{2, 1}, {7, 2}, {6, 5}, {9, 4}, {5, 9}};
float d = (float) 1e9;
for(int i=0; i<10; i++){
for(int j=i+1; j<10; j++){
float dx = a[i][0] - a[j][0];
float dy = a[i][1] - a[j][1];
d = min(d, Math.sqrt(dx*dx+dy*dy));
}
}
System.out.println(d);
}
private static float min(float d, double sqrt) {
return d = d>sqrt?d=(float) sqrt:d;
}
}

相关文章:

  • 2021-12-01
  • 2022-02-04
  • 2022-03-06
  • 2022-02-11
  • 2022-02-14
  • 2021-11-19
  • 2021-11-29
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-12-24
  • 2022-12-23
  • 2021-06-06
  • 2022-02-07
相关资源
相似解决方案