当前位置:网站首页>#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.
边栏推荐
- Rasa Chat Robot Tutorial (translation) (1)
- View and terminate the executing thread in MySQL
- I'm doing open source in Didi
- Oppo Xiaobu launched Obert, a large pre training model, and promoted to the top of kgclue
- UNIX socket advanced learning diary - advanced i/o functions
- 跨平台(32bit和64bit)的 printf 格式符 %lld 输出64位的解决方式
- RHCSA4
- 10 minute fitness method reading notes (1/5)
- 前几年外包干了四年,秋招感觉人生就这样了..
- Notes for preparation of information system project manager --- information knowledge
猜你喜欢
SAP SEGW 事物码里的 ABAP Editor
自然语言处理系列(一)入门概述
Taobao order interface | order flag remarks, may be the most stable and easy-to-use interface
DNS的原理介绍
SAP UI5 FlexibleColumnLayout 控件介绍
A few years ago, I outsourced for four years. Qiu Zhao felt that life was like this
太方便了,钉钉上就可完成代码发布审批啦!
使用 jMeter 对 SAP Spartacus 进行并发性能测试
About LDA model
Oppo Xiaobu launched Obert, a large pre training model, and promoted to the top of kgclue
随机推荐
JSON parsing error special character processing (really speechless... Troubleshooting for a long time)
A deep long article on the simplification and acceleration of join operation
Distance measuring sensor chip 4530a used in home intelligent lighting
在家庭智能照明中应用的测距传感芯片4530A
VoneDAO破解组织发展效能难题
How do e-commerce sellers refund in batches?
实现 1~number 之间,所有数字的加和
研究:数据安全工具在 60% 的情况下无法抵御勒索软件
Taobao short videos are automatically released in batches without manual RPA open source
Simply take stock reading notes (1/8)
Halcon 模板匹配实战代码(一)
2021-12-22 transaction record
Tips and tricks of image segmentation summarized from 39 Kabul competitions
RHCSA2
SAP SEGW 事物码里的 ABAP Editor
Programming skills for optimizing program performance
Talk about my drawing skills in my writing career
自然语言处理系列(一)入门概述
insmod 提示 Invalid module format
A small talk caused by the increase of sweeping