标签:des style blog http color java os io
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3209 Accepted Submission(s): 2348
2 100 200
-74.4291 -178.8534
代码如下:
<span style="font-size:14px;">#include<stdio.h> #include<stdlib.h> #include<math.h> #define eps 1e-6 double cal(double x) { return 42*pow(x,6)+48*pow(x,5)+21*pow(x,2)+10*pow(x,1); }//自己设立求导函数 double sum(double x,double y) { return 6*pow(x,7)+8*pow(x,6)+7*pow(x,3)+5*pow(x,2)-x*y; } int main() { int n; scanf("%d",&n); while(n--) { double low=0,high=100,y,mid; scanf("%lf",&y); while(high-low>eps) {//因为是double型所以比较的时候,要考虑精度的问题 mid=(high+low)/2; if(cal(mid)<y)//这是三分法,呵呵呵 导数小于零,继续因为是凹形 low=mid+1e-8; else high=mid-1e-8; } printf("%0.4lf\n",sum(mid,y)); } return 0; }</span>
该链接有关于二分法,三分法的一点小小的体会,不了解的可以去看看
http://blog.csdn.net/ice_alone/article/details/38420043
标签:des style blog http color java os io
原文地址:http://blog.csdn.net/ice_alone/article/details/38420493