Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
求救: 为什么1e-3 就TLM ,1e-2就 WA后来改成 精确到 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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator