首页 > 其他分享 >#yyds干货盘点# 名企真题专题:搬圆桌

#yyds干货盘点# 名企真题专题:搬圆桌

时间:2022-12-05 17:05:27浏览次数:41  
标签:yyds 名企 真题 nextInt long y1 sc x1 圆桌

1.简述:

描述

现在有一张半径为r的圆桌,其中心位于(x,y),现在他想把圆桌的中心移到(x1,y1)。每次移动一步,都必须在圆桌边缘固定一个点然后将圆桌绕这个点旋转。问最少需要移动几步。

输入描述:

一行五个整数r,x,y,x1,y1(1≤r≤100000,-100000≤x,y,x1,y1≤100000)

输出描述:

输出一个整数,表示答案

示例1

输入:

2 0 0 0 4

输出:

1

2.代码实现:

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);
}

}
}

标签:yyds,名企,真题,nextInt,long,y1,sc,x1,圆桌
From: https://blog.51cto.com/u_15488507/5913066

相关文章