SDAU 练习二 10002

来源:互联网 发布:township破解版无网络 编辑:程序博客网 时间:2024/05/29 17:49
 这个题与第一个题类似,也是运用二分法,只不过这个运用的数学知识更多。acm编程对数学要求也比较高。
给出一个函数,再给出Y,让你求最小值,求导会发现,这个函数先单调递减,再升,先求导,利用二分法,求倒数为0的点,在计算出来结果。
#include <cstdio>
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<math.h>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<iomanip>
using namespace std;
double y;
double eqa1(double x)
{
    return 6*x*x*x*x*x*x*x+8*x*x*x*x*x*x+7*x*x*x+5*x*x-y*x;
}
double eqa (double x)
{
    return 42*x*x*x*x*x*x+48*x*x*x*x*x+21*x*x+10*x-y;
}
int main()
{
    //freopen("r.txt","r",stdin);
    double x,r,l,mid,min;
    int N,i;
    cin>>N;
    while(N--)
    {


        cin>>y;
        l=0;
        r=100;
        while((r-l)>0.000000001)
        {
            mid=(r+l)/2;
            if(eqa(mid)>0) r=mid;
            else l=mid;
        }
        mid=eqa1(mid);
        printf("%.4f\n",mid);
    }


}
0 0
原创粉丝点击