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

    Strange fuction

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 2278    Accepted Submission(s): 1697


    Problem Description
    Now, here is a fuction:
      F(x) = 6 * x^7+8*x^6+7*x^3+5*x^2-y*x (0 <= x <=100)
    Can you find the minimum value when x is between 0 and 100.
     
    Input
    The first line of the input contains an integer T(1<=T<=100) which means the number of test cases. Then T lines follow, each line has only one real numbers Y.(0 < Y <1e10)
     
    Output
    Just the minimum value (accurate up to 4 decimal places),when x is between 0 and 100.
     
    Sample Input
    2 100 200
     
    Sample Output
    -74.4291 -178.8534
     
    Author
    Redow
     
    Recommend
    lcy   |   We have carefully selected several similar problems for you:  2289 2298 2141 3400 1969 
     
     1 //0MS    224K    590 B    G++
     2 /*
     3     
     4     题意:
     5         给出一关系式: 
     6             F(x) = 6 * x^7+8*x^6+7*x^3+5*x^2-y*x (0 <= x <=100) 
     7         和y的值,求x在范围(0,100)内时F(x)能取得的最小值
     8     
     9     二分法:
    10         很容易可以看出函数F(x)在(0,100)内是先减后增的,故用二分法求其倒数的零值点,然后用零值
    11     再代入原式即可求出最值   
    12          
    13 */
    14 #include<stdio.h>
    15 #define e 1e-7
    16 double fac(double a,double b)
    17 {
    18     return 6*a*a*a*a*a*a*a+8*a*a*a*a*a*a+7*a*a*a+5*a*a-b*a;    
    19 } 
    20 double fac0(double a,double b)
    21 {
    22     return 42*a*a*a*a*a*a+48*a*a*a*a*a+21*a*a+10*a-b;       
    23 }
    24 int main(void)
    25 {
    26     int t;
    27     double n;
    28     scanf("%d",&t);
    29     while(t--)
    30     {
    31         scanf("%lf",&n);
    32         double l=0;
    33         double r=100;
    34         while(r-l>e){
    35             double mid=(l+r)/2;
    36             if(fac0(mid,n)>0) r=mid;
    37             else l=mid;
    38         }
    39         printf("%.4lf
    ",fac(r,n));
    40     }
    41     return 0;
    42 }
  • 相关阅读:
    jQuery 遍历函数 ,javascript中的each遍历
    定时器:右下角滑动信息通知
    nopad++将制表符替换为换行符
    使用git提交远程仓库
    (转)解决windows解决windows 7 部分程序图标显示不正常的问题
    设置gvim的字体大小
    mysql乱码
    (转)notepad++去重
    查看linux硬件的信息
    虚拟机安装centos6.5出现Error processing drive:pci-0000:00:10-scsi-0:0:0:0问题
  • 原文地址:https://www.cnblogs.com/GO-NO-1/p/3426069.html
Copyright © 2011-2022 走看看