代码实现:
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); } } }