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

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

HDU - 2899 Strange fuction 二分/三分

2019-11-09 21:15:19
字體:
來源:轉載
供稿:網友

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; }
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 陆丰市| 亳州市| 醴陵市| 布拖县| 酒泉市| 孝感市| 汝州市| 怀柔区| 杂多县| 崇左市| 连云港市| 奉节县| 营山县| 广东省| 横峰县| 武城县| 夏津县| 长治市| 托克逊县| 永宁县| 旌德县| 横山县| 广水市| 任丘市| 青浦区| 囊谦县| 井陉县| 肥乡县| 虎林市| 韶山市| 蓝山县| 舒城县| 高尔夫| 左权县| 金川县| 安达市| 惠来县| 华宁县| 青海省| 体育| 正定县|