当前位置:网站首页>#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.
边栏推荐
- Insmod prompt invalid module format
- Shi Zhenzhen's 2021 summary and 2022 outlook | colorful eggs at the end of the article
- 自然语言处理系列(一)入门概述
- From the perspective of technology and risk control, it is analyzed that wechat Alipay restricts the remote collection of personal collection code
- Using MySQL in docker
- A few years ago, I outsourced for four years. Qiu Zhao felt that life was like this
- SAP SEGW 事物码里的 ABAP 类型和 EDM 类型映射的一个具体例子
- 使用 jMeter 对 SAP Spartacus 进行并发性能测试
- JSON parsing error special character processing (really speechless... Troubleshooting for a long time)
- 实战模拟│JWT 登录认证
猜你喜欢
SAP UI5 DynamicPage 控件介绍
stm32和电机开发(从架构图到文档编写)
函数传递参数小案例
你的下一台电脑何必是电脑,探索不一样的远程操作
Simply take stock reading notes (4/8)
Taobao, pinduoduo, jd.com, Doudian order & Flag insertion remarks API solution
HiEngine:可媲美本地的云原生内存数据库引擎
Didi open source Delta: AI developers can easily train natural language models
stirring! 2022 open atom global open source summit registration is hot!
Add a new cloud disk to Huawei virtual machine
随机推荐
ActiveMQ installation and deployment simple configuration (personal test)
Taobao order amount check error, avoid capital loss API
10 minute fitness method reading notes (5/5)
Distributed solution - completely solve website cross domain requests
How can labels/legends be added for all chart types in chart. js (chartjs.org)?
Neural network of PRML reading notes (1)
Lepton 无损压缩原理及性能分析
【云原生】Nacos-TaskManager 任务管理的使用
Wechat enterprise payment to change access, open quickly
RHCSA4
太方便了,钉钉上就可完成代码发布审批啦!
跨平台(32bit和64bit)的 printf 格式符 %lld 输出64位的解决方式
SAP UI5 DynamicPage 控件介绍
Principle of universal gbase high availability synchronization tool in Nanjing University
LeetCode20.有效的括号
Install rhel8.2 virtual machine
开发者,云原生数据库是未来吗?
Simply take stock reading notes (3/8)
逆波兰表达式
HiEngine:可媲美本地的云原生内存数据库引擎