二分---LIGHTOJ 1062
| 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 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 |
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;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
二分---LIGHTOJ 1062的更多相关文章
- LightOJ 1062 - Crossed Ladders 基础计算几何
http://www.lightoj.com/volume_showproblem.php?problem=1062 题意:问两条平行边间的距离,给出从同一水平面出发的两条相交线段长,及它们交点到水平 ...
- 二分--LIGHTOJ 1088查找区间(水题)
#include <iostream> #include <cstdio> #include <cmath> using namespace std; const ...
- LightOj 1138 - Trailing Zeroes (III) 阶乘末尾0的个数 & 二分
题目链接:http://lightoj.com/volume_showproblem.php?problem=1138 题意:给你一个数n,然后找个一个最小的数x,使得x!的末尾有n个0:如果没有输出 ...
- lightOJ 1132 Summing up Powers(矩阵 二分)
题目链接:http://lightoj.com/volume_showproblem.php?problem=1132 题意:给出n和m.求sum(i^m)%2^32.(1<=i<=n) ...
- LightOJ 1138 Trailing Zeroes (III)(二分 + 思维)
http://lightoj.com/volume_showproblem.php?problem=1138 Trailing Zeroes (III) Time Limit:2000MS M ...
- LightOJ 1088 - Points in Segments 二分
http://www.lightoj.com/volume_showproblem.php?problem=1088 题意:给出N个点,Q个查询,问在区间内的点数有多少个. 思路:直接在线二分,注意边 ...
- LightOj 1088 - Points in Segments (二分枚举)
题目链接: http://www.lightoj.com/volume_showproblem.php?problem=1088 题目描述: 给出一个n位数升序排列的数列,然后q个查询,每个查询问指定 ...
- lightoj 1138 - Trailing Zeroes (III)【二分】
题目链接:http://lightoj.com/volume_showproblem.php? problem=1138 题意:问 N. 末尾 0 的个数为 Q 个的数是什么? 解法:二分枚举N,由于 ...
- Lightoj 1235 - Coin Change (IV) 【二分】
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1235 题意: 有N个硬币(N<=18).问是否能在每一个硬币使用不超过两 ...
随机推荐
- 第一部分 CLR基础:第2章 生成、打包、部署和管理应用程序及类型
2.1.NET Framework部署目标 Microsoft Windows多年来因不稳定和复杂而口碑不佳.造成的原因:1.应用程序都使用来自微软和厂商的动态链接库(dynamic-link lib ...
- 记一次动态调用WebService
这次的使用参考博客园中的ID是 生命不息,折腾不止 http://www.cnblogs.com/leolion/p/4757320.html ,感谢分享 博客园让自己慢慢的成长,少不了这些无私奉献 ...
- C# Datetime类常用技巧
C#类常用技巧 //今天DateTime.Now.Date.ToShortDateString();//昨天,也就是今天的日期减一DateTime.Now.AddDays(-1).ToShortDat ...
- [转发]导出Excel 格式 mso-number-format
应用中经常会遇到要从系统或数据库中导出数据平面文件,一般是导出到txt,csv或excel.txt和csv一般用在系统间的数据交换,而 excel一般有较好的显示效果,可以按照一定的模板导出,导出就不 ...
- 《安全参考》HACKCTO-201312-12
小编的话 “忽如一夜春风来,千树万树梨花开.” 小伙伴们,不要只为了“千树万树的梨花”而惊喜,陶醉! 与此同时,您最爱的整合型信息安全技术期刊<安全参考>第12期也如约而至啦! 这一期&l ...
- 在xml中添加array
在values建立arrays(名字可自定义)的xml: <?xml version="1.0" encoding="utf-8"?> <re ...
- Linq操作
Linq使用Group By 1 1.简单形式: var q = from p in db.Products group p by p.CategoryID into g select g; 语句描述 ...
- 社保系列7《PSAM卡》
PSAM卡用于商户POS.网点终端.直联终端等端末设备上,负责机具的安全控管.PSAM卡具有一定的通用性.经过个人化处理的PSAM卡能在不同的机具上使用. PSAM卡支持多级发卡的机制,各级发卡方在卡 ...
- Collaborative filtering
Collaborative filtering, 即协同过滤,是一种新颖的技术.最早于1989年就提出来了,直到21世纪才得到产业性的应用.应用上的代表在国外有Amazon.com,Last. ...
- JavaScript高级程序设计之函数性能
setTimeout 比 setInterval 性能更好 // 取代setInterval setTimeout(function self () { // code goes here setTi ...
