4.26腾讯笔试第二题,出错在哪里呀?本地用例可以通过,求大神指点
题目简介:求出给定两组坐标中,欧氏距离最小的数,结果保留3位小数
保存调试是0.0%
import java.util.*; public class Main{ public static void main(String[] args) { Scanner in = new Scanner(System.in); int n=in.nextInt(); List<point> A=new ArrayList<>(); List<point> B=new ArrayList<>(); in.nextLine(); for(int i=0;i<n;i++){ String str=in.nextLine(); String[] t=str.split(" "); A.add(new point(Integer.parseInt(t[0]),Integer.parseInt(t[1]))); } for(int i=0;i<n;i++){ String str=in.nextLine(); String[] t=str.split(" "); B.add(new point(Integer.parseInt(t[0]),Integer.parseInt(t[1]))); } double min=Math.sqrt(Math.pow(A.get(0).x-B.get(0).x,2)+Math.pow(A.get(0).y-B.get(0).y,2)); for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ point a=A.get(i); point b=B.get(j); double temp=Math.sqrt(Math.pow(a.x-b.x,2)+Math.pow(a.y-b.y,2)); if(min>temp){ min=temp; } } } System.out.printf("%.3f",min); } public static class point{ int x; int y; public point(int x, int y){ this.x=x; this.y=y; } } }
全部评论
(2) 回帖