三次方根

Posted by 磊落 on May 11, 2020

三次方根

思想

  • 二分查找

特点

#include <iostream>
#include <algorithm>

using namespace std;



int main()
{
    double x;
    cin >> x;

    double l = -1e4, r = 1e4;

    while (r - l > 1e-8)
    {
        double mid = (l + r) / 2;
        if (mid * mid * mid >= x) r = mid;
        else l = mid;
    }
    
    printf("%.6lf", l);

    return 0;
}