POJ2507 Crossed ladders(几何推公式+二分)
2017-11-22 13:23
239 查看
Link:http://poj.org/problem?id=2507
Crossed ladders
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
Sample Output
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;
}
Crossed ladders
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 5209 | Accepted: 1980 |
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;
}
相关文章推荐
- Crossed ladders---poj2507(二分+简单几何)
- poj-2507-Crossed ladders【二分】【计算几何】
- poj 2507Crossed ladders 计算几何,二分
- UVa 10566 Crossed Ladders 平面几何结论,二分答案
- Crossed Ladders - UVa 10566 二分几何
- UVA 10566 Crossed Ladders (几何题,二分)
- poj 2507 crossed ladders(计算几何,二分)
- 【二分+几何】E - Crossed Ladders
- uva 10566 - Crossed Ladders(几何+二分)
- UVA 10566 Crossed Ladders (几何+二分)
- poj2507 Crossed ladders 二分
- uva 10566 Crossed ladders(二分 + 几何)
- POJ:2507 Crossed ladders(二分+几何数学)
- 算法竞赛宝典 分治算法 交叉的梯子(几何公式的推导+二分)
- LightOJ 1062 Crossed Ladders(二分)
- POJ 2507Crossed ladders(二分)
- 【UVa】10566 - Crossed Ladders(二分 & 数学)
- POJ1905 Expanding Rods(计算几何推公式+二分)
- poj2507 Crossed ladders
- UVA 10566 Crossed Ladders (几何题)