zoukankan      html  css  js  c++  java
  • hdu 2899 Strange Fuction(二分)

    简单二分,但这个不满足单调性。

    题目要求极值点,以函数导数的正负作为条件二分即可。

    code:

    #include<cstdio>
    #include<cmath>
    double y = 0 ;
    double cal(double x){
        return 42*pow(x, 6.0) + 48*pow(x, 5.0) + 21*pow(x, 2.0) + 10*x - y ;
    }
    double solve(double x){
        return 6*pow(x, 7.0) + 8*pow(x, 6.0) + 7*pow(x, 3.0) + 5*pow(x, 2.0) - y*x ;
    }
    int main(){
        int t ;
        double r, l, m ;
        scanf("%d", &t) ;
        while(t--){
            scanf("%lf", &y) ;
            if(cal(100)<=0){    //x=100时若导数小于0,则函数满足单调递减
                                
    //因为42*pow(x, 6.0) + 48*pow(x, 5.0) + 21*pow(x, 2.0) + 10*x递增,x=100时有最大值
                                
    //不过官方数据好像没有用到这个剪枝
                printf("%.4lf\n", solve(100)) ;
                continue ;
            }
            l = 0 ;
            r = 100 ;
            while(r-l>1e-8){
                m = (r + l) / 2 ;
                double ans = cal(m) ;
                if(ans<0)
                    l = m ;
                else
                    r = m ;
            }
            printf("%.4lf\n", solve(m)) ;
        }
        return 0 ;
    }

  • 相关阅读:
    hdoj--2098--分拆素数和(枚举)
    hdoj--3594--Cactus(tarjan)
    hdoj--1251--统计难题(字典树)
    hdoj--2534--Score(gcd)
    nyoj--1185--最大最小值(线段树)
    hdoj--1166--敌兵布阵(线段树)
    hdoj--1754--I Hate It(线段树)
    poj--2234--Matches Game(尼姆博弈)
    lightoj--1005--Rooks(组合数)
    SPOJ
  • 原文地址:https://www.cnblogs.com/xiaolongchase/p/2351949.html
Copyright © 2011-2022 走看看