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;

        }
    }
}



#腾讯2021届暑期实习正式批笔试##笔试题目##腾讯#
全部评论
两个for过不了的
点赞 回复 分享
发布于 2020-08-10 22:08
用int应该是不行的,用的double
点赞 回复 分享
发布于 2020-04-26 22:53

相关推荐

点赞 评论 收藏
分享
评论
4
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务