zoukankan      html  css  js  c++  java
  • HDU2899 (二分)

    题意:由题意给出的函数,求出最小值的x

    方法一

    先求导,导数等于0的位置就是F(x)最小的位置

    ( 仅限此题)

    View Code
     1 #include<stdio.h>
     2 #include<math.h>
     3 
     4 double func( double x,double y ){
     5     double ans;
     6     ans=42.0*pow( x,6.0 )+48.0*pow( x,5.0 )+21.0*x*x+10.0*x-y;
     7     return ans;
     8 }
     9 
    10 double func2( double x,double y ){
    11     double ans;
    12     ans=6.0*pow(x,7.0)+8.0*pow(x,6.0)+7.0*pow(x,3.0)+5.0*pow(x,2.0)-y*x;
    13     return ans;
    14 }
    15 
    16 int main(){
    17     int T;
    18     scanf("%d",&T);
    19     while( T-- ){
    20         double y;
    21         scanf("%lf",&y);
    22         double left,right,mid;
    23         left=0,right=100.0;
    24         double delta=1e-8;
    25         while( left<right ){
    26             mid=( left+right )/2.0;
    27             double temp;
    28             temp=func( mid,y );
    29             if( temp==0 ) break;
    30             if( temp>0 ) right=mid-delta;
    31             else left=mid+delta;
    32         }
    33         printf("%.4lf\n",func2( mid,y ));
    34     }
    35     return 0;
    36 }
    keep moving...
  • 相关阅读:
    20140710 sequence 前缀和
    20140709 testC 数学题
    20140708 testA 组合数学
    20140708 testB DP 组合数学
    Sad :(
    已经是一个废人了……
    Game Theory
    HDU Math Problems
    2-sat问题
    并查集
  • 原文地址:https://www.cnblogs.com/xxx0624/p/2878706.html
Copyright © 2011-2022 走看看