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): 5253    Accepted Submission(s): 3750


    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
     
     
     
    解析:要求F(x)=6*x^7+8*x^6+7*x^3+5*x^2-y*x(0<=x<=100)的最小值,可以求F(x)的导数F'(x)来研究F(x)。易知:对于任意的y(0<y<1e10),F'(0)<0,F'(100)>0。而F'(x)在区间(0,100)上单调递增(因为F(x)的二阶导数F''(x)在区间(0,100)上恒大于0),故在区间(0,100)上必存在x0,使得F'(x0)=0。这个点是F(x)的极小值点,就是F(x)在区间(0,100)的最小值点。可以用二分法求出x0,代入F(x)即可。
     
     
     
     1 #include <cstdio>
     2 #include <cmath>
     3 
     4 double f(double x,double y)
     5 {
     6     return 6*pow(x,7)+8*pow(x,6)+7*pow(x,3)+5*pow(x,2)-y*x;
     7 }
     8 
     9 double f1(double x,double y)
    10 {
    11     return 42*pow(x,6)+48*pow(x,5)+21*pow(x,2)+10*x-y;
    12 }
    13 
    14 int main()
    15 {
    16     int T,y;
    17     scanf("%d",&T);
    18     while(T--){
    19         scanf("%d",&y);
    20         double low = 0,high = 100;
    21         while(high-low>1e-6){
    22             double mid = (low+high)/2;
    23             if(f1(mid,y)<0)
    24                 low = mid+1e-8;
    25             else
    26                 high = mid-1e-8;
    27         }
    28         double x0 = (low+high)/2;
    29         printf("%.4f
    ",f(x0,y));
    30     }
    31     return 0;
    32 }

    本题也可用三分。

     1 #include <cstdio>
     2 #include <cmath>
     3 
     4 double f(double x,double y)
     5 {
     6     return 6*pow(x,7)+8*pow(x,6)+7*pow(x,3)+5*pow(x,2)-y*x;
     7 }
     8 
     9 int main()
    10 {
    11     int T,y;
    12     scanf("%d",&T);
    13     while(T--){
    14         scanf("%d",&y);
    15         double low = 0,high = 100;
    16         double lowmid,highmid;
    17         while(high-low>1e-6){
    18             lowmid = (2*low+high)/3;
    19             highmid = (low+2*high)/3;
    20             if(f(lowmid,y)<f(highmid,y))
    21                 high = highmid-1e-8;
    22             else
    23                 low = lowmid+1e-8;
    24         }
    25         printf("%.4f
    ",f(low,y));
    26     }
    27     return 0;
    28 }
  • 相关阅读:
    vnpy源码阅读学习(8):关于app
    vnpy源码阅读学习(6):事件引擎
    vnpy源码阅读学习(5):关于MainEngine的代码阅读
    tensorflow 2.1 采坑记
    vnpy源码阅读学习(4):自己写一个类似vnpy的UI框架
    ABP (.Net Core 3.1版本) 使用MySQL数据库迁移启动模板项目(1)
    'vue-cli-service' 不是内部或外部命令,也不是可运行的程序 或批处理文件。
    C# Winform版批量压缩图片程序
    小程序开发技巧总结
    ASP.NET WebAPI 双向token实现对接小程序登录逻辑
  • 原文地址:https://www.cnblogs.com/inmoonlight/p/5182431.html
Copyright © 2011-2022 走看看