AcWing 790. 数的三次方根
原题链接
简单
作者:
不知名的fE
,
2024-11-20 19:36:18
,
所有人可见
,
阅读 1
轮子实现
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
double n = sc.nextDouble();
double l = -10000, r = 10000;
while (r - l > 1e-8) {//注意要比题目精度大二即可
double mid = (l + r) / 2;
if (mid * mid * mid > n) r = mid;
else l = mid;
}
System.out.printf("%.6f", r);
}
}
库函数Math.cbrt(cube root)函数求解
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
double n = sc.nextDouble();
double ans = Math.cbrt(n);
System.out.printf("%.6f", ans);
}
}