HDU 2899 Strange fuction (求導解方程+二分尋找),hdufuction

來源:互聯網
上載者:User

HDU 2899 Strange fuction (求導解方程+二分尋找),hdufuction

題目連結:click here~~

【題目大意】:

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.給你一個方程,求其給定範圍內的最小值。

【解題思路】:

首先,對該式子,求一階導,得到F'(x) = 42*x^6 + 48*x^5+21*x^2+10*x-y,這裡,我們忽略y,可發現,導函數42*x^6 + 48*x^5+21*x^2+10*x是遞增的,範圍在[0, 10^13],
所以我們可以發現無論y取什麼值,總可以找到x1∈[0, 100],使F'(x1)=0,又因為此時x∈[0, x1]時,函數遞減(導函數小於零,原函數遞減,反之,遞增);x∈[x1, 100]時,函數遞增。所以F(x1)便是極小值,也是最小值。綜上,先對F'(x)使用二分法即可,最後結果輸出F(x)的值即可

代碼:

 
#include <bits/stdc++.h>using namespace std;const double eps=1e-6;int t;double y;double fun(double x){    return 6*pow(x,7)+8*pow(x,6)+7*pow(x,3)+5*pow(x,2)-y*x;}double func(double x){    return 42*pow(x,6)+48*pow(x,5)+21*pow(x,2)+10*x-y;}int main(){    //freopen("1.txt","r",stdin);    scanf("%d",&t);    while(t--)    {        scanf("%lf",&y);        double ll=0,rr=1e2,mid;        while(ll+eps<=rr){            mid=(ll+rr)/2;;            if(func(mid)>0) rr=mid;             else ll=mid;        }        printf("%.4f\n",fun(mid));    }    return 0;}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.