当前位置:网站首页>#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.
边栏推荐
- View and terminate the executing thread in MySQL
- How to connect the API interface of Taobao open platform (super detailed)
- Database connection pool & jdbctemplate
- Iterator details in list... Interview pits
- HiEngine:可媲美本地的云原生内存数据库引擎
- JDBC -- use JDBC connection to operate MySQL database
- Pinduoduo flag insertion remarks API
- 从39个kaggle竞赛中总结出来的图像分割的Tips和Tricks
- 逆波兰表达式
- Tips and tricks of image segmentation summarized from 39 Kabul competitions
猜你喜欢

Taobao short videos are automatically released in batches without manual RPA open source

Lepton 无损压缩原理及性能分析

Volatile instruction rearrangement and why instruction rearrangement is prohibited

I met Tencent in the morning and took out 38K, which showed me the basic smallpox

How to connect the API interface of Taobao open platform (super detailed)

研究:数据安全工具在 60% 的情况下无法抵御勒索软件

Transactions from December 27 to 28, 2021

Four common problems of e-commerce sellers' refund and cash return, with solutions

RHCSA7

开发者,云原生数据库是未来吗?
随机推荐
开发者,云原生数据库是未来吗?
NLP engineer learning summary and index
Reshape the power of multi cloud products with VMware innovation
A deep long article on the simplification and acceleration of join operation
自然语言处理从小白到精通(四):用机器学习做中文邮件内容分类
What is the difference between Bi software in the domestic market
使用 jMeter 对 SAP Spartacus 进行并发性能测试
关于 SAP UI5 floating footer 显示与否的单步调试以及使用 SAP UI5 的收益
【云原生】Nacos-TaskManager 任务管理的使用
【Nacos云原生】阅读源码第一步,本地启动Nacos
SAP SEGW 事物码里的 Association 建模方式
Distributed solution - distributed lock solution - redis based distributed lock implementation
RHCSA5
Time conversion error
View and modify the MySQL data storage directory under centos7
SAP UI5 FlexibleColumnLayout 控件介绍
Oppo Xiaobu launched Obert, a large pre training model, and promoted to the top of kgclue
Taobao short videos are automatically released in batches without manual RPA open source
Lepton 无损压缩原理及性能分析
超高效!Swagger-Yapi的秘密