您的位置:首页 > 其它

POJ2507 Crossed ladders(几何推公式+二分)

2017-11-22 13:23 239 查看
Link:http://poj.org/problem?id=2507

Crossed ladders

Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 5209 Accepted: 1980
Description

A narrow street is lined with tall buildings. An x foot long ladder is rested at the base of the building on the right side of the street and leans on the building on the left side. A y foot long ladder is rested at the base of the building on the left side
of the street and leans on the building on the right side. The point where the two ladders cross is exactly c feet from the ground. How wide is the street? 



Input

Each line of input contains three positive floating point numbers giving the values of x, y, and c.
Output

For each line of input, output one line with a floating point number giving the width of the street in feet, with three decimal digits in the fraction.
Sample Input
30 40 10
12.619429 8.163332 3
10 10 3
10 10 1

Sample Output
26.033
7.000
8.000
9.798

Source

The UofA Local 2000.10.14

AC code:

#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<string.h>
#include<map>
#include<set>
#define LL long long
#define INF 0xfffffff
#define PI acos(-1)
#define EPS 1e-6
using namespace std;

double x,y,c;

double fun(double z)
{
return 1-c/sqrt(y*y-z*z)-c/sqrt(x*x-z*z);
}

double Bsearch(double low,double high)
{
double mid;
while(high-low>EPS)
{
mid=(low+high)/2;
if(fun(mid)>0)
{
low=mid;
}
else
{
high=mid;
}
}
return mid;
}

int main()
{
// freopen("in.txt","r",stdin);
double low,high,ans;
while(~scanf("%lf%lf%lf",&x,&y,&c))
{
low=0;
high=min(x,y);
ans=Bsearch(low,high);
printf("%.3f\n",ans);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: