ACW.790数的三次方根

image.png

思路

  • 依照常规二分查找,寻找不满足条件区间mid * mid * mid > n的左端点即可
  • 边界条件while (right - left > 1e-7)
  • leftright不必+1,而是left = mid; else right = mid

    代码

    ```cpp

    include

using namespace std;

const int N = 1e4 + 5;

int main() { double n = 0; cin >> n; double left = -1e4, right = 1e4; while (right - left > 1e-7) { double mid = (left + right) / 2; if (double(mid mid mid) >= n) { right = mid; } else { left = mid; } }

  1. printf("%.6f", left);
  2. return 0;

} ```