![:D](./images/smilies/icon_biggrin.gif)
Should I treat it as a special case ???
Bye, Aur
Moderator: Board moderators
Code: Select all
/*Use b-search,or the bisection method to find the answer*/
#include<cstdio>
#include<cmath>
using namespace std;
double x,y,c,s,func,U,D,e,f;
int main(void)
{
while(scanf("%lf%lf%lf",&x,&y,&c)==3)
{
if(x==y&&c!=0)
{
s = sqrt(x*x-4*c*c);
printf("%.3lf\n",s);
}
else if(c==0)
{
printf("0.000\n");
}
else
{
if(x>y)
U = x;
else
U = y;
D = 0;
s = (U+D)/2;
e = sqrt(x*x-s*s);
f = sqrt(y*y-s*s);
func = (1/c)-(1/e)-(1/f);
while(abs(func)>0.0000001)
{
if(func>0)
D = s;
else
U = s;
s = (U+D)/2;
e = sqrt(x*x-s*s);
f = sqrt(y*y-s*s);
func = (1/c)-(1/e)-(1/f);
}
printf("%.3lf\n",s);
}
}
return 0;
}
Code: Select all
double wmin = 0, wmax = min(x,y);
while (fabs(wmin - wmax) > EPS) {
double w = (wmin + wmax) / 2;
double hy = sqrt(y*y - w*w);
double y0 = (c / hy) * y;
double w0 = sqrt(y0 * y0 - c * c);
double w1 = w - w0;
double x0 = sqrt(w1 * w1 + c * c);
double hx = c * (x / x0);
double wx = sqrt(x * x - hx * hx);
if (wx > w) {
wmin = w;
}
else {
wmax = w;
}
}
printf("%.3lf\n", (wmax + wmin) / 2);