二分---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).问是否能在每一个硬币使用不超过两 ...
随机推荐
- 软件工程 speedsnail 第二次冲刺3
20150520 完成任务:划线第三天,能画出一条直黄线且与蜗牛共存: 遇到问题: 问题1 碰撞检测有缺陷 解决1 没有解决 明日任务: 实现蜗牛与线的碰撞
- C#获取本周周一的日期
/// <summary> /// 获取本周的周一日期 /// </summary> /// <returns></returns> public st ...
- Zookeeper 脑裂
转自 http://blog.csdn.net/u010185262/article/details/49910301 Zookeeper zookeeper是一个分布式应用程序的协调服务.它是一个为 ...
- (转)Java操作Hbase进行建表、删表以及对数据进行增删改查,条件查询
1.搭建环境 新建JAVA项目,添加的包有: 有关Hadoop的hadoop-core-0.20.204.0.jar 有关Hbase的hbase-0.90.4.jar.hbase-0.90.4-tes ...
- php设计模式之单例、多例设计模式
单例(Singleton)模式和不常见的多例(Multiton)模式控制着应用程序中类的数量.如模式名称,单例只能实例化一次,只有一个对象,多例模式可以多次实例化. 基于Singleton的特性,我们 ...
- PHP变量作用域以及地址引用问题
作用域的概念: 在PHP脚本的任何位置都可以声明变量,但是,声明变量的位置会大大影响访问变量的范围.这个可以访问的范围称为作用域. 主要的常用的包括:局部变量.全局变量.静态变量. 1.局部变量:就是 ...
- Java排序
给出10个数,使用某种排序方法,按照从小到大的顺序输出个个数. 根据要求,首先得给出这10个数,这里的算法需要一个循环,数据结构需要一个长度为10的整型数组.首先用BufferedReader in= ...
- 【转】在delphi中实现控件的拖拽
提示:可以添加一个布尔来控制可否拖动的状态,这里提供所有都能拖动的方法. procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseB ...
- SPARK 数据统计程序性能优化。
昨天写完R脚本 没测试就发到博客里, 结果实际运行发现很慢,运行时间在2小时以上, 查看spark控制台, 大量时间消耗在count上, 产生的stage多大70多个 . 分析原因. 1 selec ...
- Hello World程序
本文最初发表于2015-8-??,是由别的地方迁移过来的 本文利用改写内存的办法在屏幕中央显示“Hello world”字符串. 首先我们需要了解80*25彩色字符模式显示缓冲区的结构. 〉〉内存中B ...