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

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

HDU-2899

2019-11-10 18:31:18
字體:
來源:轉載
供稿:網友
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));    }}


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 竹山县| 承德县| 利津县| 水富县| 安宁市| 海兴县| 西充县| 潜江市| 宣威市| 温泉县| 漠河县| 久治县| 洛阳市| 澳门| 长乐市| 堆龙德庆县| 江油市| 固安县| 衢州市| 蓝田县| 秭归县| 淳安县| 桃江县| 太和县| 南丰县| 怀化市| 竹山县| 当阳市| 平阴县| 崇文区| 井冈山市| 乌什县| 阳信县| 安塞县| 伊宁县| 江都市| 广河县| 本溪市| 罗城| 石棉县| 响水县|