数据范围:|val| \le 20 \∣val∣≤20
待求解参数,为double类型(一个实数)
输出参数的立方根。保留一位小数。
代码如下:
#include<iostream> #include<cmath> using namespace std; int main(){ double v; while(cin>>v){ double left, right; left = v>-1?-1:v; right = v>1?v:1; double val; while(fabs(right - left) > 1e-8){ val = (left+right)/2; if(v - val*val*val <= 1e-8){ right = val; }else{ left = val; } } printf("%.1lf\n",val); } }