标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4538 Accepted Submission(s):
3261
1 #include<stdio.h> 2 #include<math.h> 3 double hs(double x,double y) 4 { 5 return 6*pow(x,7)+8*pow(x,6)+7*pow(x,3)+5*x*x-y*x;//定义一个求函数值得函数 6 } 7 double ds(double x,double y) 8 { 9 return 42*pow(x,6)+48*pow(x,5)+21*pow(x,2)+10*x-y;//定义一个求导数的函数 10 } 11 int main() 12 { 13 int a; 14 scanf("%d",&a); 15 while(a--) 16 { 17 double b,x,y,z; 18 scanf("%lf",&b); 19 x=0.0; 20 y=100.0; 21 do 22 { 23 z=(x+y)/2; 24 if(ds(z,b)>0) 25 y=z; 26 else 27 x=z; 28 }while(y-x>1e-6);//求出一定精度内导数为0的大约值 29 printf("%.4lf\n",hs(z,b)); 30 } 31 return 0; 32 }
1 #include<stdio.h> 2 #include<math.h> 3 double hs(double x,double y) 4 { 5 return 6*pow(x,7)+8*pow(x,6)+7*pow(x,3)+5*x*x-y*x; 6 } 7 int main() 8 { 9 int n; 10 scanf("%d",&n); 11 while(n--) 12 { 13 double l,r,mid,midmid,a; 14 scanf("%lf",&a); 15 l=0.0; 16 r=100.0; 17 do 18 { 19 mid=(l+r)/2; 20 midmid=(mid+r)/2; 21 if(hs(mid,a)>hs(midmid,a)) 22 l=mid; 23 else 24 r=midmid; 25 }while(r-l>1e-6); 26 printf("%.4lf\n",hs(mid,a)); 27 } 28 return 0; 29 }
标签:
原文地址:http://www.cnblogs.com/Eric-keke/p/4677187.html