hdu 2199

基本的二分,但是我还是提交了几次,因为那个er开大了,超时了……

#include "stdio.h"
#include "math.h"
#define er 1e-4//这里的er我起初开到了1e-7……超时了……

int main()
{
 int T;
 double n,t,u,d,a;

 scanf("%d",&T);
 while(T--)
 {
  scanf("%lf",&n);

  n=n-6;
  if(n<0||n>(8*10000-100+3)*101*100)
  {
   printf("No solution!\n");
   continue;
  }

  if(n==0)
  {
   printf("0.0000\n");
   continue;
  }

  a=(8*2500-50+3)*51*50;
  t=50;
  u=0;
  d=100;
  while(fabs(a-n)>er)
  {
   if(a-n>0)
   {
    d=t;
    t=(t+u)/2;
   }
   else
   {
    u=t;
    t=(t+d)/2;
   }
   a=(8*t*t-t+3)*(t+1)*t;//这个式子是我化简后的……
  }

  printf("%.4lf\n",t);
 }
 return 0;
}
    

原文地址:https://www.cnblogs.com/Shirlies/p/2357966.html