题解 | #搬圆桌#

搬圆桌

http://www.nowcoder.com/practice/81bb01ef2bb144808a8277e9164a0886

import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n =0;
        double distance =0;
        while(sc.hasNext()){
            // 使用long防止大数相乘溢出int范围
            int r = sc.nextInt();
            long x = sc.nextInt();
            long y = sc.nextInt();
            long x1 = sc.nextInt();
            long y1 = sc.nextInt();
            double a=(x1-x)*(x1-x)+(y1-y)*(y1-y);
            distance=Math.sqrt(a);
            n = (int)distance/(2*r);
            // 若最后不能整除,需要再旋转一次
            if((n*2*r)<distance){
                n++;
            }
            System.out.println(n);
        }
        
    }
}
全部评论

相关推荐

04-17 18:32
门头沟学院 Java
野猪不是猪🐗:他跟你一个学校,你要是进来之后待遇比他好,他受得了?
点赞 评论 收藏
分享
评论
5
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务