题解 | #使徒袭来#

使徒袭来

https://ac.nowcoder.com/acm/problem/209794

#include <bits/stdc++.h>
using namespace std;

float f(float(*fx)(float), float y, float jd){
    float left  = 0;
    float right = y;
    float  x    = 0;
    float  fy   = 0;
    
    while(right - left > jd){
        x = (left + right) / 2;
        fy = fx(x);
        if(fy == y){
            break;
        }else if (fy > y){
            right  = x;
        }else if (fy < y){
            left = x;            
        }
    }
    return x;
}

float f1(float x){
    return x * x * x;
}

int main(){
    int n;
    cin >> n;    
    printf("%.3f", f(f1, n, 0.0001) * 3);
    return 0;
}
全部评论

相关推荐

09-09 09:17
已编辑
东华理工大学 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务