现在的位置: 首页 > 综合 > 正文

Strange fuction

2012年08月08日 ⁄ 综合 ⁄ 共 472字 ⁄ 字号 评论关闭
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
double fun1(double x,double y)
{
  return 6*x*x*x*x*x*x*x+8*x*x*x*x*x*x+7*x*x*x+5*x*x-y*x;
}
double fun2(double x,double y)
{
  return 42*x*x*x*x*x*x+48*x*x*x*x*x+21*x*x+10*x-y;
}
int main( )
{
  int N;
  double M,a,b,mid;
  scanf("%d",&N);
  while(N--)
  {
   a=0,b=100,mid=50;
   scanf("%lf",&M);
   while(fabs(fun2(mid,M))>1e-4)
   {
    mid=(a+b)/2;
    if(fun2(mid,M)>=0)
    b=mid;
    else
    a=mid;
   }
   printf("%.4lf\n",fun1(mid,M));
}
return 0;
}
   
            
/*思路就是先求导,然后根据数学知识,求出其导数为0时的x,就是最小值。
【上篇】
【下篇】

抱歉!评论已关闭.