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): 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;
    }
  • 相关阅读:
    CI 知识 :Git介绍及常用操作
    虚拟机的迁移(热迁移)
    kvm虚拟化网络管理
    Zabbix -----安装
    Mariadb 主从
    keepalived + lvs marster 与 backup 之间的 高可用
    LVS 负载均衡 (VS/DR模式 与 VS/TUN 模式)
    linux下部署tomcat 上线jpress博客系统
    docker (2)---存储、网络(利用docker容器上线静态网站)
    openstack(2) -------RabbitMQ集群部署
  • 原文地址:https://www.cnblogs.com/Noevon/p/5331058.html
Copyright © 2011-2022 走看看