Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

求救: 为什么1e-3 就TLM ,1e-2就 WA

Posted by xianyunsc at 2005-07-27 23:39:42 on Problem 2507
  后来改成 精确到 3e-3 仍然超时,请高手指点,谢谢了!
 我的代码如下:
#include<stdio.h>
#include<math.h>
 float f(float r)
 { float t;
    t=(1.0/r)*(1.0/r)-1.0/((1.0-r)*(1.0-r));
   return t;
 }
int main()
{int i;
 float x,y,c,r,k,n,m,t,len;
 while(scanf("%f%f%f",&x,&y,&c)==3)
 { k=(x*x-y*y)/(c*c);
     n=0;  m=1;  t=0.5;
   while(fabs(f(t)-k)>1e-3)
   { t=(m+n)/2.0;
     if(f(t)>k)  n=t;
	   else m=t;
   }
  len=x*x-(c*c)/(t*t);
  len=sqrt(len);
  printf("%.3f\n",len);
 }
  return 0;
}
   不知其它的迭代是怎样的。

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator