10分 1个点AC 8个点MLE(内存超限) 1个点WA
查看原帖
10分 1个点AC 8个点MLE(内存超限) 1个点WA
580868
juchenglin楼主2023/2/21 21:12
#include <iostream>
#include<iomanip>
using namespace std;
double getValue(double a, double b, double target)
{
    double ret = (a + b)/2;
    double val = ret*ret*ret;
    if((val - target) * (val - target) < 0.0001)
        return ret;
    if(val*val > target*target)
        return getValue(a, ret, target);
    else if(val*val < target*target)
        return getValue(ret, b, target);
}
double getCubeRoot(double input)
{
    if(input < 1.0)
        return getValue(input, 1.0, input);
    if(input > 1.0)
        return getValue(1.0, input, input);
}
int main()
{
    double a, b;
    cin >> a;
    b = getCubeRoot(a);
    cout <<  setprecision(2) << b << endl;
    return 0;
}
2023/2/21 21:12
加载中...