0

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

 1 year ago
source link: https://blog.51cto.com/u_15488507/5913066
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

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

精选 原创

97的风 2022-12-05 16:49:32 博主文章分类:面试题 ©著作权

文章标签 System Math java 文章分类 Java 编程语言 阅读数163

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

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

}
}

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK