poj-2507-Crossed ladders【二分】【计算几何】
来源:互联网 发布:传奇 放技能 编程 编辑:程序博客网 时间:2024/06/06 20:23
Crossed ladders
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 5007 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
这是拍的第一道计算几何,刚开始就没想到要用数学公式,我个脑残,看了别人的思路
题意:两栋楼之间有两个梯子,如图中的虚线所示,一个梯子的长度为x,另一个梯子的长度为y,两个梯子的交点离地面的高度为c,问两栋楼之间的距离。
这是一个几何题。设宽度为w,交点距左楼距离为a,则根据三角形相似可以推出:
把第二个式子代入第一个式子可以得出一个等式,把方程左边写成关于w的函数,求导可得是减函数。因为w一定小于x,y中的最小值(三角形的直角边小于斜边),二分求出答案即可。
#include<cstdio> #include<cmath> #include<algorithm> using namespace std; double x,y,c; double judge(double w) { return 1-c/sqrt(x*x-w*w)-c/sqrt(y*y-w*w); }int main() { while(~scanf("%lf %lf %lf",&x,&y,&c)) { double left=0,mid,right=max(x,y); while(right-left>1e-8) { mid=(left+right)/2; if(judge(mid)>0) left=mid; else right=mid; } printf("%.3lf\n",mid); } return 0; }
题意:两栋楼之间有两个梯子,如图中的虚线所示,一个梯子的长度为x,另一个梯子的长度为y,两个梯子的交点离地面的高度为c,问两栋楼之间的距离。
这是一个几何题。设宽度为w,交点距左楼距离为a,则根据三角形相似可以推出:
把第二个式子代入第一个式子可以得出一个等式,把方程左边写成关于w的函数,求导可得是减函数。因为w一定小于x,y中的最小值(三角形的直角边小于斜边),二分求出答案即可。
0 0
- poj 2507 crossed ladders(计算几何,二分)
- poj 2507Crossed ladders 计算几何,二分
- poj-2507-Crossed ladders【二分】【计算几何】
- UVA 10566 - Crossed Ladders(二分+计算几何)
- POJ:2507 Crossed ladders(二分+几何数学)
- 【二分+几何】E - Crossed Ladders
- Crossed Ladders(二分+几何)
- POJ 2507 Crossed ladders (二分)
- poj 2507 Crossed ladders
- POJ-2507 Crossed ladders
- POJ - 2507 Crossed Ladders
- UVA 10566 && POJ 2507 Crossed Ladders (几何)
- Crossed Ladders - UVa 10566 几何+二分
- Crossed Ladders - UVa 10566 二分几何
- uva 10566 - Crossed Ladders(几何+二分)
- uva 10566 Crossed ladders(二分 + 几何)
- UVA 10566 Crossed Ladders (几何+二分)
- POJ 2507 Crossed ladders 笔记
- 278. First Bad Version
- PRML学习
- 欢迎使用CSDN-markdown编辑器
- 顺序表查询
- HDOJ 2199 Can you solve this equation?【水】
- poj-2507-Crossed ladders【二分】【计算几何】
- 总结CSS Sprites优缺点
- hdu 5752 Sqrt Bo(水)
- 本地通知
- mvn plugin
- MySQL 使用方法简单教程
- 面试准备之--桶类排序
- Cable master poj 1064
- 用栈实现汉诺塔