当前位置:网站首页>#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.
边栏推荐
- Common commands and basic operations of Apache Phoenix
- Distributed cache architecture - cache avalanche & penetration & hit rate
- JDBC -- extract JDBC tool classes
- Alipay transfer system background or API interface to avoid pitfalls
- Docker configures redis and redis clusters
- Simply take stock reading notes (4/8)
- MySQL 巨坑:update 更新慎用影响行数做判断!!!
- RHCSA7
- Kotlin process control and circulation
- Yyds dry inventory JS intercept file suffix
猜你喜欢
Compilation principle reading notes (1/12)
RHCSA3
Oppo Xiaobu launched Obert, a large pre training model, and promoted to the top of kgclue
CVPR 2022 | 基于稀疏 Transformer 的单步三维目标识别器
Research: data security tools cannot resist blackmail software in 60% of cases
RHCSA7
Lepton 无损压缩原理及性能分析
From the perspective of technology and risk control, it is analyzed that wechat Alipay restricts the remote collection of personal collection code
自然语言处理系列(一)入门概述
SAP UI5 DynamicPage 控件介绍
随机推荐
自然语言处理系列(一)入门概述
RHCSA7
leetcode:221. 最大正方形【dp状态转移的精髓】
SAP 自开发记录用户登录日志等信息
Volatile instruction rearrangement and why instruction rearrangement is prohibited
单独编译内核模块
跨平台(32bit和64bit)的 printf 格式符 %lld 输出64位的解决方式
前几年外包干了四年,秋招感觉人生就这样了..
SAP UI5 ObjectPageLayout 控件使用方法分享
Introduction to relational model theory
CF:A. The Third Three Number Problem【关于我是位运算垃圾这个事情】
在家庭智能照明中应用的测距传感芯片4530A
Research: data security tools cannot resist blackmail software in 60% of cases
Introduction to the principle of DNS
946. 验证栈序列
Pinduoduo flag insertion remarks API
10 minute fitness method reading notes (3/5)
JDBC -- use JDBC connection to operate MySQL database
逆波兰表达式
Annotation problem and hidden Markov model