数据相乘易错点

1.现在有一张半径为r的圆桌,其中心位于(x,y),现在他想把圆桌的中心移到(x1,y1)。每次移动一步,都必须在圆桌边缘固定一个点然后将圆桌绕这个点旋转。问最少需要移动几步。

解决方案:

public static void main(String[] args) {//1941 4776 3688 -45690 3688
Scanner sc=new Scanner(System.in);
/*long r=sc.nextLong();
long x=sc.nextLong();
long y=sc.nextLong();
long x1=sc.nextLong();
long y1=sc.nextLong();*/
int r=sc.nextInt();
int x=sc.nextInt();
int y=sc.nextInt();
int x1=sc.nextInt();
int y1=sc.nextInt();
getRes(r,x,y,x1,y1);
}
public static void getRes(int r, int x, int y, int x1, int y1) {
double sum=(long)Math.sqrt((x-x1)*(x-x1)+(y-y1)*(y-y1));//int类型数据相乘得到的结果值不能超过int类型的取值范围
if(sum%(2*r)==0){
System.out.println((int)(sum/(2*r)));
}else{
System.out.println((int)(sum/(2*r)+1));
}
}

猜你喜欢

转载自blog.csdn.net/ylf_2278880589/article/details/80674937