题解 | #求解立方根#
求解立方根
https://www.nowcoder.com/practice/caf35ae421194a1090c22fe223357dca
#include <iostream> #include<stdio.h> using namespace std; int main() { double x; cin>>x; double i; if(x>1){ i=1.0; while(i*i*i<=x){ i+=0.1; } i-=0.1; while(i*i*i<x){ i+=0.01; } }else{ i=1.0; while( i*i*i > x){ i-=0.1; } i+=0.1; while(i*i*i >x){ i-=0.01; } } printf("%.1f",i); return 0; } // 64 位输出请用 printf("%lld")
先粗查找,到附近了再精确查找