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

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

HDU - 2899 Strange fuction 二分/三分

2019-11-10 18:59:42
字體:
來源:轉載
供稿:網友

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; }
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 静宁县| 南郑县| 南投市| 泗阳县| 诸城市| 丰顺县| 西和县| 防城港市| 固始县| 龙口市| 子长县| 土默特左旗| 泰兴市| 雅江县| 阿拉善左旗| 霍山县| 仪征市| 隆尧县| 邻水| 沅陵县| 如东县| 宝鸡市| 桃江县| 财经| 桂林市| 彭水| 东阿县| 体育| 阿拉尔市| 东至县| 多伦县| 姜堰市| 镶黄旗| 黄陵县| 大方县| 方城县| 读书| 农安县| 双江| 黔南| 行唐县|