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

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

HDU - 2899 Strange fuction 二分/三分

2019-11-09 20:37:47
字體:
來源:轉載
供稿:網友

Strange fuction

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.

Input

The 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)

Output

Just the minimum value (accurate up to 4 decimal places),when x is between 0 and 100.

Sample Input

2 100 200

Sample Output

-74.4291 -178.8534

這題有兩個思路,都需要一點數學 一個思路是可以明顯看出這個函數在[0,100]上是一個凹函數,那么由此可以使用三分 另一個思路是利用最值點導數值為0這一性質,于是我們也可以采用二分 我用的是后一種思路,不多說直接上代碼吧

代碼

#include <cmath>#include <iostream>using namespace std;double y;double f(double x);long double f_p(double x);int main(){ int N; double mid,high,low; cin>>N; while(N--){ cin>>y; high=100,low=0; mid=(low+high)/2; while((fabs(f_p(mid))>1e-4)){ if(f_p(mid)<0){ low=mid; }else{ high=mid; } mid=(low+high)/2; }
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 磐石市| 旺苍县| 英山县| 甘泉县| 南木林县| 旺苍县| 渝中区| 南澳县| 共和县| 九江县| 静海县| 辽阳县| 临汾市| 德格县| 玉门市| 磴口县| 鄂伦春自治旗| 自治县| 佛山市| 阜康市| 公安县| 衡水市| 咸阳市| 黑水县| 岐山县| 奇台县| 潍坊市| 白河县| 泌阳县| 开远市| 宝坻区| 和静县| 巴马| 且末县| 定边县| 布尔津县| 治多县| 轮台县| 台南市| 泽州县| 永济市|