日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【HDU - 2899】 Strange fuction(二分或三分,求导)

發布時間:2023/12/10 编程问答 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【HDU - 2899】 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,所以一階導數是單調的,所以求一次導數后用二分法,或者不求導用三分法亦可解。

AC代碼:

#include<bits/stdc++.h>using namespace std; const double eps = 1e-6; double y; bool cal(double x) {double sum=0;sum = 42*(x*x*x*x*x*x) + 48*(x*x*x*x*x) + 21*(x*x) + 10*x -y; if(sum<0) return 0;else return 1; } double acal(double x) {double sum = 0;sum =6*(x*x*x*x*x*x*x) + 8*(x*x*x*x*x*x) + 7*(x*x*x) + 5*(x*x) -y*x ;return sum; } int main() {int t;double mid,l,r;cin>>t;while(t--) {scanf("%lf",&y);l = 0;r = 100;if(cal(l) == 1) {printf("%.4f\n",acal(l));continue;}else if(cal(r) == 0) {printf("%.4f\n",acal(r));continue;}mid = (l+r)/2;while(r-l>=eps) {mid = (l+r)/2;if(cal(mid)) r = mid;else l = mid;}printf("%.4f\n",acal(mid));}return 0 ; }

總結:

? ?事實證明這題用精度1e-6或者1e-8都可以過。?

總結

以上是生活随笔為你收集整理的【HDU - 2899】 Strange fuction(二分或三分,求导)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。