HDU 2899 - Strange fuction (三分)

题目:https://vjudge.net/contest/312328#problem/A

题意:二分 找函数的最小值 (三分? 学到的 hhh )

          mid and midmid

#include<bits/stdc++.h>
using namespace std;

int n,a;
double f(double x)
{
    return 6*pow(x,7)+8*pow(x,6)+7*pow(x,3)+5*pow(x,2)-a*x;
}
int main()
{
    cin >> n; 
    while(n--) {
        double l, r, mid, midmid;
        cin >> a;
        l = 0, r = 100;
        while(r - l > 1e-6) {
            mid = l+(r-l)/2;
            midmid = mid+(r-mid)/2;
            if(f(mid) > f(midmid)) l = mid;
            else r = midmid;
        }
        printf("%.4lf\n",f(mid));
    }
    return 0;
}
View Code

 

posted @ 2019-07-25 10:06  愉也  阅读(148)  评论(0编辑  收藏  举报