zoukankan      html  css  js  c++  java
  • Strange fuction






    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.
    InputThe 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) OutputJust 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


    题意:输入一个Y,求方程的最小解。

    题解:用三分法,注意精度。

    AC代码为;

    #include<iostream>
    #include<cmath>
    #include<cmath>
    #include<algorithm>


    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)-y*x;
    }


    int main()
    {
    int T;
    double y;

    cin>>T;

    while(T--)
    {
    cin>>y;
    double t1,t2,mid1,mid2;
    t1=0,t2=100;
    for(int i=0;i<200;i++)
    {
    mid1=(t1+t2)/2;
    mid2=(mid1+t2)/2;

    if(f(mid1,y)>f(mid2,y))
    {
    t1=mid1;
    }
    else
    {
    t2=mid2;
    }

    }
    printf("%.4lf ",f(mid1,y));
    }

    return 0;
    }


  • 相关阅读:
    NSCache
    编译器 perforSelecter时 警告去除
    常用git命令
    LINUX系统自动化部署shell脚本
    个人工作总结10
    个人工作总结09
    个人工作总结-8
    个人工作总结07
    第八周学习进度
    对搜狗输入法的一些评价
  • 原文地址:https://www.cnblogs.com/csushl/p/9386636.html
Copyright © 2011-2022 走看看