hdu_2899_Strange fuction(三分查找)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=2899
题意:让你解方程
题解:对于只有一个凸或者没有凸的图像,可以直接上三分解决、
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include<cstdio> 2 #include<cmath> 3 double eps=1e-7; 4 int t,y; 5 double f(double x){return 6*pow(x,7)+8*pow(x,6)+7*pow(x,3)+5*pow(x,2)-y*x;} 6 double three_search(){ 7 double l=0,r=100,mid,mmid; 8 while(l+eps<r){ 9 mid=(l+r)/2,mmid=(mid+r)/2; 10 if(f(mid)>f(mmid))l=mid;else r=mmid; 11 } 12 return f(l); 13 } 14 int main(){ 15 scanf("%d",&t); 16 while(t--){ 17 scanf("%d",&y); 18 printf("%.4lf\n",three_search()); 19 } 20 return 0; 21 }