Posted on 2008-10-20 21:07
Hero 阅读(184)
评论(0) 编辑 收藏 引用 所属分类:
代码如诗--ACM
1 //2507 Accepted 328K 0MS G++ 742B PKU
//两个梯子的方程
2
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <string.h>
6 #include <math.h>
7
8 double x, y, c ;
9
10 const double eps = 1e-6 ;
11
12 double fmin( double a, double b )
13 {
14 if( a - b > 0 ) return b ;
15 else return a ;
16 }
17
18 double f( double z )
19 {
20 double reval = 0.0 ;
21 reval += c / sqrt( (x*x)-(z*z) ) ;
22 reval += c / sqrt( (y*y)-(z*z) ) ;
23 reval -= 1 ;
24
25 return reval ;
26 }
27
28 int main()
29 {
30 while( scanf( "%lf %lf %lf", &x, &y, &c ) != EOF )
31 {
32 double left = 0.0 ; double right = fmin( x, y ) ; double mid ;
33
34 while( right - left > eps )
35 {
36 mid = (right+left)/2 ;
37 if( f( mid ) > 0 )
38 {
39 right = mid ;
40 }
41 else
42 {
43 left = mid ;
44 }
45 }
46
47 printf( "%0.3lf\n", mid ) ;
48 }
49
50 return 0 ;
51 }