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

首頁(yè) > 學(xué)院 > 開(kāi)發(fā)設(shè)計(jì) > 正文

HDU-2899

2019-11-09 20:10:23
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
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

這道題在做的時(shí)候,最開(kāi)始覺(jué)得這個(gè)函數(shù)應(yīng)該是用三分法解決,但是用了之后,會(huì)發(fā)現(xiàn)怎么都ac不了,都是

wa,然后在網(wǎng)上查完資料之后,發(fā)現(xiàn)這道題就應(yīng)該是先求導(dǎo),之后再根據(jù)導(dǎo)數(shù)的正負(fù),來(lái)運(yùn)用二分法解決問(wèn)

題,因?yàn)槲覀円蟮氖且粋€(gè)最值而跟極值的概念還是有不同的,之后將過(guò)程實(shí)現(xiàn),就可以ac了,這道題感覺(jué)

就是可以運(yùn)用數(shù)學(xué)知識(shí)解決問(wèn)題

#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));    }}


發(fā)表評(píng)論 共有條評(píng)論
用戶(hù)名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 陆丰市| 嵩明县| 横峰县| 漳平市| 南溪县| 浮梁县| 汉川市| 蚌埠市| 明溪县| 霍林郭勒市| 青阳县| 青州市| 大洼县| 马尔康县| 乐安县| 若尔盖县| 金坛市| 湖北省| 长兴县| 阜新| 沧州市| 武隆县| 囊谦县| 大足县| 萝北县| 开封市| 蚌埠市| 会泽县| 如皋市| 太康县| 芮城县| 武城县| 墨脱县| 东乡| 乌兰浩特市| 虞城县| 合肥市| 龙里县| 吉安县| 萝北县| 吉隆县|