杭电--2899 三分法

阅读更多
#include
#include
#include
#include
#include
using namespace std;

double cal(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;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%lf",&y);
        double mid ,midmid;
        double left=0.0;
        double right=100.0;
        while((right-left)>1e-6)
        {
            mid=(left+right)/2;
            midmid=(mid+right)/2;
            if(cal(mid,y)                right=midmid;
            else left=mid;
        }
        printf("%.4lf\n",cal(left,y));
    }
return 0;
}

你可能感兴趣的:(生活)