当前位置:网站首页>#yyds干货盘点# 解决名企真题:搬圆桌
#yyds干货盘点# 解决名企真题:搬圆桌
2022-07-05 12:40:00 【51CTO】
1.简述:
描述
现在有一张半径为r的圆桌,其中心位于(x,y),现在他想把圆桌的中心移到(x1,y1)。每次移动一步,都必须在圆桌边缘固定一个点然后将圆桌绕这个点旋转。问最少需要移动几步。
输入描述:
一行五个整数r,x,y,x1,y1(1≤r≤100000,-100000≤x,y,x1,y1≤100000)
输出描述:
输出一个整数,表示答案
示例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);
}
}
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
边栏推荐
- jxl笔记
- Preliminary exploration of basic knowledge of MySQL
- SAP UI5 FlexibleColumnLayout 控件介绍
- How can labels/legends be added for all chart types in chart. js (chartjs.org)?
- 单独编译内核模块
- Reshape the power of multi cloud products with VMware innovation
- Distributed solution - Comprehensive decryption of distributed task scheduling platform - xxljob scheduling center cluster
- 使用 jMeter 对 SAP Spartacus 进行并发性能测试
- 实现 1~number 之间,所有数字的加和
- A small talk caused by the increase of sweeping
猜你喜欢

SAP SEGW 事物码里的导航属性(Navigation Property) 和 EntitySet 使用方法

From the perspective of technology and risk control, it is analyzed that wechat Alipay restricts the remote collection of personal collection code

Taobao order interface | order flag remarks, may be the most stable and easy-to-use interface

国内市场上的BI软件,到底有啥区别

Transactions from December 29, 2021 to January 4, 2022

Notes for preparation of information system project manager --- information knowledge

Kotlin变量

HiEngine:可媲美本地的云原生内存数据库引擎

2021.12.16-2021.12.20 empty four hand transaction records

Setting up sqli lab environment
随机推荐
ActiveMQ installation and deployment simple configuration (personal test)
你的下一台电脑何必是电脑,探索不一样的远程操作
Taobao order amount check error, avoid capital loss API
Transactions from December 29, 2021 to January 4, 2022
Distance measuring sensor chip 4530a used in home intelligent lighting
leetcode:221. 最大正方形【dp状态转移的精髓】
How can labels/legends be added for all chart types in chart. js (chartjs.org)?
Simply take stock reading notes (4/8)
非技术部门,如何参与 DevOps?
Wechat enterprise payment to change access, open quickly
Talk about my drawing skills in my writing career
Full text search of MySQL
Sqoop import and export operation
Using MySQL in docker
10 minute fitness method reading notes (1/5)
太方便了,钉钉上就可完成代码发布审批啦!
stm32和电机开发(从架构图到文档编写)
Distributed solution - Comprehensive decryption of distributed task scheduling platform - xxljob scheduling center cluster
Insmod prompt invalid module format
Difference between JUnit theories and parameterized tests