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
Input starts with an integer T (≤ 10), denoting the number of test cases.
Each test case contains three positive floating point numbers giving the values of x, y, and c.
Output
For each case, output the case number and the width of the street in feet. Errors less than 10-6 will be ignored.
Sample Input
4
30 40 10
12.619429 8.163332 3
10 10 3
10 10 1
Sample Output
Case 1: 26.0328775442
Case 2: 6.99999923
Case 3: 8
Case 4: 9.797958971
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
int main()
{
int t,test=1;
scanf("%d",&t);
double x,y,c;
while(t--){
scanf("%lf%lf%lf",&x,&y,&c);
double l=0,r=min(x,y);
int Size=100;
while(Size--){
double mid=(l+r)/2.0;
double angle1=acos(mid/x);//角度1
double angle2=acos(mid/y);//角度2
double d=c/tan(angle1)+c/tan(angle2);
if(d<mid)
l=mid;
else
r=mid;
}
printf("Case %d: %.7lf\n",test++,l);
}
return 0;
}

本文探讨了一道经典的几何问题——交叉梯子问题。该问题涉及两座相邻建筑间放置的不同长度梯子,通过数学方法计算街道宽度。文章提供了一种使用数值逼近方法求解的C++实现。
2358

被折叠的 条评论
为什么被折叠?



