hdu2899水题

有了2199的基础,不用20分钟水掉。嘿嘿,一遍

#include<stdio.h>
#include<math.h>
double f1(double z,double z1)
{
 return 6*z*z*z*z*z*z*z+8*z*z*z*z*z*z+7*z*z*z+5*z*z-z1*z;
}

double f2(double z,double z1)
{
 return 42*z*z*z*z*z*z+48*z*z*z*z*z+21*z*z+10*z-z1;
}

int main()
{
 int t,k;
 double y,l,r,mid,fz;
 scanf("%d",&t);
 while(t--)
 {
  scanf("%lf",&y);
  l=0.0;    r=100.0;
  if(y<=0)                          //说明这种情况是单调递增的
  {
   printf("%.4lf\n",f1(0,y));
   continue;
  }
  else
  {
   if(f2(100,y)<=0)               //说明这种情况是单调递减的
   {
    printf("%.4lf\n",f1(100,y));
   }
   else                       //这种情况是 先递减,后递增的
   {
    k=0;
    while(r-l>1e-6)
    {
     mid=(l+r)/2.0;
        fz=f2(mid,y);
        if(fz==0)
        {
      k=1;
      printf("%.4lf\n",f1(mid,y));
      break;
     }
        if(fz>0)
        r=mid-1e-6;
        else
        l=mid+1e-6;
    }
    if(k==0)
    {
     mid=(l+r)/2;
     printf("%.4lf\n",f1(mid,y));
    }
   }
  }
 }
 return 0;
}

posted on 2012-02-21 16:02  hrbust_09zhangyabin  阅读(184)  评论(0编辑  收藏  举报