国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

HDU-2899

2019-11-09 20:54:03
字體:
來源:轉載
供稿:網友
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
2100200Sample Output
-74.4291

-178.8534

這道題在做的時候,最開始覺得這個函數應該是用三分法解決,但是用了之后,會發現怎么都ac不了,都是

wa,然后在網上查完資料之后,發現這道題就應該是先求導,之后再根據導數的正負,來運用二分法解決問

題,因為我們要求的是一個最值而跟極值的概念還是有不同的,之后將過程實現,就可以ac了,這道題感覺

就是可以運用數學知識解決問題

#include<iostream>#include<cmath>#include<cstdio>using namespace std;double cal(double x,double y){    //6 * x^7+8*x^6+7*x^3+5*x^2-y*x (0 <= x <=100)    return(6*pow(x,7)+8*pow(x,6)+7*pow(x,3)+5*pow(x,2)-y*x);}double cal_d(double x,double y){    return(42*pow(x,6)+48*pow(x,5)+21*pow(x,2)+10*x-y);}int main(){    int times;    cin>>times;    while(times--)    {        long long y_get;        cin>>y_get;        double low = 0,high = 100;        double mid;        while(low<high-0.000001)        {            mid = (low+high)/2;            if(cal_d(mid,y_get)>0) high = mid;            else low = mid;        }        PRintf("%.4f/n",cal(mid,y_get));    }}


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 姜堰市| 神农架林区| 广东省| 陇西县| 南通市| 临夏县| 绥德县| 同仁县| 芮城县| 建平县| 建阳市| 长岛县| 鹤壁市| 阿克| 斗六市| 西贡区| 电白县| 吉木萨尔县| 云阳县| 承德县| 漯河市| 若尔盖县| 闻喜县| 都安| 大邑县| 曲靖市| 宁波市| 尤溪县| 女性| 北川| 保靖县| 嘉鱼县| 定州市| 靖远县| 鹤岗市| 万州区| 西乡县| 酒泉市| 高雄市| 临夏市| 郴州市|