• HDU 2899 Strange fuction 二分


    Strange fuction

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

    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
     
    题目大意:第一行T,接下来输入T个Y,求方程F(x) = 6 * x^7+8*x^6+7*x^3+5*x^2-y*x (0 <= x <=100)最小值。
    思路:求导,把导函数等于0的X值计算出来,代入原方程就是最小值。(好像有什么三分......没写,下次写下)
     
    数学方法:
    #include <iostream>
    #include <math.h>
    double y;
    double vv(double x)
    {
        return (6*pow(x,7)+8*pow(x,6)+7*pow(x,3)+5*pow(x,2)-x*y);
    }
    double v(double x)
    {
        return (42*pow(x, 6)+48*pow(x, 5)+21*pow(x, 2)+10*x-y);    
    }
    double f(double x,double z,double y)
    {
        double mid;
        while((y-z)>1e-10)
        {
        mid = (y+z)/2;
        if(v(mid)<x)
        z=mid+1e-10;
        else
        y=mid-1e-10;
        }
        return mid;
    }
    int main()
    {
        int a, T;
        scanf("%d", &T);
        while(T--)
        {
            scanf("%lf", &y);
            printf("%.4lf
    ", vv(f(0,0,100)));    
        }    
        return 0;
    }

     三分:

    #include <iostream>
    #include <stdio.h>
    #include <math.h>
    using namespace std;
    double f(double x, double y)
    {
        return (6*pow(x,7)+8*pow(x,6)+7*pow(x,3)+5*pow(x,2)-x*y);
    }
    int main()
    {
        int a, T, t;
        double mid1,mid2, z, y;
        cin>>T;
        while(T--)
        {
            z=0;y=100;t=50;
            cin>>a;
            while(t--){
            mid1=(z+y)/2;
            mid2=(mid1+y)/2;
            if(f(mid1,a)<f(mid2,a))
            y=mid2;
            else
            z=mid1;
            }
            printf("%.4lf
    ", f(mid1,a));
        }
        return 0;
    }
  • 相关阅读:
    AWTK-MVVM 在 STM32H743 上的移植笔记
    windows 中文 unicode 编码显示
    SpringBoot项目jar包运行
    Activiti中的互斥网关、并行网关、兼容网关、事件网关
    【LeetCode】739.每日温度(5种方法,详细图解)
    【LeetCode】20.有效的括号(使用栈,动图详解)
    你知道权限管理的RBAC模型吗?
    关闭Win10自动更新
    iOS 中如何判断当前是2G/3G/4G/5G/WiFi
    GCD API 记录 (三)
  • 原文地址:https://www.cnblogs.com/Noevon/p/5331058.html
Copyright © 2020-2023  润新知