首页 > 4.26腾讯笔试第二题,本地用例可以通过,求大神指点
头像
charles201810141428794
编辑于 2020-04-27 09:11
+ 关注

4.26腾讯笔试第二题,本地用例可以通过,求大神指点

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) 回帖
加载中...
话题 回帖

推荐话题

相关热帖

历年真题 真题热练榜 24小时
技术(软件)/信息技术类
查看全部

近期精华帖

热门推荐