poj 2507 Crossed ladders
来源:互联网 发布:齐鲁软件大赛2016 编辑:程序博客网 时间:2024/06/11 11:23
Crossed ladders
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 5012 Accepted: 1921
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
题解:设要求的边为w,交点到左边墙的距离为a,则根据三角形相似得 (w-a)/w = c/sqrt(y*y-w*w)......(1)
a/w = c/sqrt(x*x-w*w)......(2) 由(1)(2)式得到 c/sqrt(y*y-w*w)+c/sqrt(x*x-w*w) = 1 。利用二分法求w的值,注意精确度。。。。代码如下
#include<cstdio>#include<cmath>#include<iostream>#include<algorithm>#define eps 1e-10using namespace std;int main(){ double x, y, c; while(~scanf("%lf%lf%lf",&x,&y,&c)) { double l = 0.0 , r = x < y ? x : y; int size = 100; while(size--) { double mid = (l + r) / 2; if( c / sqrt(x * x - mid * mid) + c / sqrt(y * y - mid * mid) <= 1) { l = mid + eps; } else r = mid - eps; } printf("%.3lf\n",l); } return 0;}
0 0
- poj 2507 Crossed ladders
- POJ-2507 Crossed ladders
- POJ - 2507 Crossed Ladders
- POJ 2507 Crossed ladders 笔记
- poj 2507 crossed ladders(计算几何,二分)
- LightOJ 1062 & Poj 2507 Crossed Ladders
- poj 2507Crossed ladders 计算几何,二分
- poj 2507 Crossed ladders 二分解方程
- POJ 2507 Crossed ladders (二分)
- poj-2507-Crossed ladders【二分】【计算几何】
- UVA 10566 && POJ 2507 Crossed Ladders (几何)
- POJ:2507 Crossed ladders(二分+几何数学)
- POJ-2057 Crossed Ladders (二分,数学)
- Crossed ladders
- Crossed Ladders
- Crossed Ladders
- Crossed Ladders
- FZU 1148 Crossed ladders
- php 发送邮件到邮箱
- *max_element
- iOS install failed 真机调试安装失败原因总结(持续更新)
- python httplib学习笔记
- hdu 1846 Brave Game (巴什博弈)
- poj 2507 Crossed ladders
- 对map集合进行排序
- 多线程的死锁程序
- 微信公众号开发教程[013]-用户管理
- Vector抛出异常与Object转换为Double后进行大小比较
- linux 服务器时间同步
- UVa - 1615 Highway 高速公路 贪心+区间选点 重庆一中高2018级竞赛班第五次测试 2016.7.26 Problem 1
- FTP主动与被动传输引发的协议那些事
- c++ 模板