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 |
二分超时=死循环In Reply To:没道理呀,也是用二分 ,超时 Posted by:wangguanjin at 2005-07-28 00:11:52 > 是不是 有那个测试数据超时呢?帮忙分析一下 > #include<stdio.h> > #include<math.h> > > float f(float x,float y,float c,float L) > { > return (sqrt((y*y-L*L)*(x*x-L*L)))/(sqrt(x*x-L*L)+sqrt(y*y-L*L))-c; > } > > int main() > { > float x,y,c; > float down,min,up,temp,L,temp1; > while(EOF!=scanf("%f %f %f",&x,&y,&c)){ > down=0.0; > if(x<y) up=x; > else up=y; > min=(down+up)/2; > L=min; > temp=f(x,y,c,L); > > temp1=temp; > if(temp1<0) temp1=-temp1; > while(temp1>0.0001){ > if(temp<0) up=min; > > if(temp>0) down=min; > min=(down+up)/2; > L=min; > temp=f(x,y,c,L); > > temp1=temp; > if(temp1<0) temp1=-temp1; > } > printf("%.3f\n",L); > > > } > > return 0; > } > /* > > 30 40 10 > 12.619429 8.163332 3 > 10 10 3 > 10 10 1 > > */ Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator