尤其注意
1、x可能是负数
2、x绝对值小于1时,开方后变大,
#include <iostream>
using namespace std;
double x;
int main(){
scanf("%lf", &x);
double l = 0, r = x, mid;
if (x > -1 && x < 1) l = -1, r = 1;
else if (x < 0) swap(l ,r);
while (r - l > 1e-7){
mid = (l + r) / 2;
if (mid * mid * mid > x) r = mid;
else l = mid;
}
printf("%f\n", l);
return 0;
}