uva 10566 二分

#include <bits/stdc++.h>
#define Min(a,b) a<=b?a:b;
using namespace std;
double x, y, c, mid;
double get_b(double a)
{
	return (a * x - a * (sqrt(a * a + c * c))) / sqrt(a * a + c * c);
}
double fun(double a)
{
	double b = get_b(a);
	return (a + b) * sqrt(b * b + c * c) - b * y;
}
int main(int argc, char const *argv[])
{
	while (~scanf("%lf%lf%lf", &x, &y, &c))
	{
		double l = 0, r = Min(x, y);
		while (r - l > 1e-8)
		{
			mid = (l + r) / 2;
			if (fun(mid) < 0) l = mid;
			else r = mid;
		}
		printf("%.3lf\n", mid + get_b(mid));
	}
	return 0;
}



列方程,二分即可。


你可能感兴趣的:(uva 10566 二分)