POJ 2507 Crossed ladders (二分)

来源:互联网 发布:melt it down 编辑:程序博客网 时间:2024/06/04 00:27
Crossed ladders
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 5002 Accepted: 1919

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 1012.619429 8.163332 310 10 310 10 1

Sample Output

26.0337.0008.0009.798

Source

The UofA Local 2000.10.14
三角函数
#include<stdio.h>#include<string.h>#include<algorithm>#include<math.h>using namespace std;int main(){double x,y,c,a1,a2;int t;int k=1;scanf("%d",&t);while(t--){scanf("%lf%lf%lf",&x,&y,&c);int size=100;double ans;double left=0;double right=min(x,y);while(size--){double mid=(left+right)/2;a1=acos(mid/x);a2=acos(mid/y);if(c/tan(a1)+c/tan(a2)<=mid){ans=mid;left=mid;}elseright=mid;}printf("Case %d: %lf\n",k++,ans);}}


0 0