二分---LIGHTOJ 1062

1062 - Crossed Ladders
Time Limit: 2 second(s)Memory Limit: 32 MB

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 xy, 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

Output for Sample Input

4

30 40 10

12.619429 8.163332 3

10 10 3

10 10 1

Case 1: 26.0328775442

Case 2: 6.99999923

Case 3: 8

Case 4: 9.797958971

 


大意:求底的长度;


找关系:设x与左边楼的交点为A,与右边楼的交点为C,y与左边楼的交点为B,与右边楼的交点为D;x与y的交点为E,由E向地面做垂线,设垂足为F。由三角形相似:EF/AB=CF/CB=1-(BF/BC)=1-(EF/CD),也就是EF/AB=1-(EF/CD),两边同时除以EF


注意:输出精度

#include<stdio.h>
#include<math.h>
#define eps 1e-9
#define min(a,b) ((a)<(b)?(a):(b))
int main(){
	int t;
	double a,b,c,high,low,mid;
	scanf("%d",&t);
//	cout<<min(t,a);
	for(int i=1;i<=t;i++){
		scanf("%lf%lf%lf",&a,&b,&c);  
		 high=min(a,b);
		 low=0;
	
		while(high-low>eps){
			mid=(high+low)/2;
			if((1/sqrt(a*a-mid*mid)+1/sqrt(b*b-mid*mid))>1/c)  //说明mid偏大
				high=mid;
			else low=mid;
		}
		printf("Case %d: %.8lf\n",i,mid);
	}
	return 0;
}



版权声明:本文为博主原创文章,未经博主允许不得转载。

posted on 2014-08-05 10:18 france 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/france/p/4808686.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值