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 |
也是二分的,不知道哪里错了?#include <iostream> #include <fstream> #include <cstdio> #include <cmath> using namespace std; int main () { #ifndef ONLINE_JUDGE freopen ("Crossed ladders.txt","r",stdin); #endif double x,y,c; double max,min,mid,dis; x = y = c = 0.0; while (scanf ("%lf%lf%lf",&x,&y,&c) != EOF) { x = x * x; y = y * y; if ( x > y) { max = sqrt (y - c * c) + 0.00001; } else { max = sqrt (x - c * c) + 0.00001; } min = 0.0; while (true) { mid = (max + min) / 2.0; dis = (1.0 / sqrt (x - mid * mid) + 1.0 / sqrt ( y - mid * mid)) - 1.0 / c; if (fabs(dis) <= 0.000001) { printf ("%.3lf\n",mid); break; } else if (dis > 0) { max = mid; } else { min = mid; } } x = y = c = 0.0; } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator