Crossed Ladders 求街道宽度 (二分法)
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
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
4
30 40 10
12.619429 8.163332 3
10 10 3
10 10 1
Sample Output
Case 1: 26.0328775442
Case 2: 6.99999923
Case 3: 8
Case 4: 9.797958971
纯数学题,
设宽度为w,交点距左楼距离为a,
#include<cstdio>
#include<cmath>
#include <algorithm>
using namespace std;
double x,y,c;
double f(double a)
{
return (-c/sqrt(x*x-a*a)-c/sqrt(y*y-a*a));
}
int main()
{
double l,r,mid;
int t;
int num=;
scanf("%d",&t);
while(t--)
{ scanf("%lf %lf %lf",&x,&y,&c);
l=;
r=min(x,y);
while(r-l > 1e-)
{
mid=(l+r)/2.0;
if(f(mid) > )
{
l=mid;
}
else
{
r=mid;
}
}
printf("Case %d: ",++num);
printf("%.7lf\n",l); }
}
Crossed Ladders 求街道宽度 (二分法)的更多相关文章
- Gym - 101635K:Blowing Candles (简单旋转卡壳,求凸包宽度)
题意:给定N个点,用矩形将所有点覆盖,要求矩形宽度最小. 思路:裸体,旋转卡壳去rotate即可. 最远距离是点到点:宽度是点到边. #include<bits/stdc++.h> #de ...
- LightOJ 1062 - Crossed Ladders 基础计算几何
http://www.lightoj.com/volume_showproblem.php?problem=1062 题意:问两条平行边间的距离,给出从同一水平面出发的两条相交线段长,及它们交点到水平 ...
- uva 10566 Crossed Ladders (二分)
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...
- POJ 2185 Milking Grid (KMP,求最小覆盖子矩阵,好题)
题意:给出一个大矩阵,求最小覆盖矩阵,大矩阵可由这个小矩阵拼成.(就如同拼磁砖,允许最后有残缺) 正确解法的参考链接:http://poj.org/showmessage?message_id=153 ...
- 二分---LIGHTOJ 1062
1062 - Crossed Ladders PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB A ...
- HOJ题目分类
各种杂题,水题,模拟,包括简单数论. 1001 A+B 1002 A+B+C 1009 Fat Cat 1010 The Angle 1011 Unix ls 1012 Decoding Task 1 ...
- lightoj刷题日记
提高自己的实力, 也为了证明, 开始板刷lightoj,每天题量>=1: 题目的类型会在这边说明,具体见分页博客: SUM=54; 1000 Greetings from LightOJ [简单 ...
- sicily 题目分类
为了方便刷题,直接把分类保存下来方便来找. 转自:http://dengbaoleng.iteye.com/blog/1505083 [数据结构/图论] 1310Right-HeavyTree笛卡尔树 ...
- SVM – 线性分类器
感知机 要理解svm,首先要先讲一下感知机(Perceptron),感知机是线性分类器,他的目标就是通过寻找超平面实现对样本的分类:对于二维世界,就是找到一条线,三维世界就是找到一个面,多维世界就是要 ...
随机推荐
- 同一台服务器上部署多个Tomcat的配置修改方法
同一服务器部署多个tomcat时,存在端口号冲突的问题,所以需要修改tomcat配置文件server.xml,以tomcat7为例. 首先了解下tomcat的几个主要端口: <Server po ...
- Homebrew 常用命令
Homebrew 常用命令 Homebrew 介绍 Homebrew也称brew,macOS下基于命令行的最强大软件包管理工具,使用Ruby语言开发.类似于CentOS的yum或者Ubuntu的apt ...
- RHEL6.5----LVS(NAT)
主机名 IP 所需软件 master 192.168.30.130(Nat) 192.168.17.130(VMnet4) ipvsadm node-1 192.168.17.131 http ...
- Hadoop调度框架
大数据协作框架是一个桐城,就是Hadoop2生态系统中几个辅助的Hadoop2.x框架.主要如下: 1,数据转换工具Sqoop 2,文件搜集框架Flume 3,任务调度框架Oozie 4,大数 ...
- poj2139 Six Degrees of Cowvin Bacon
思路: floyd 实现: #include <iostream> #include <cstdio> #include <cstring> #include &l ...
- python绘图工具包 matplotlib 中文乱码问题
环境: python2.7 windows 8.1 解决: 改配置文件,把字体改为支持中文的字体. 找到python安装目录下的 \Lib\site-packages\matplotlib\mpl-d ...
- yum install perl-ExtUtils-MakeMaker
Can't locate ExtUtils/MakeMaker.pm in @INC (@INC contains: /usr/local/lib/perl5 /usr/local/share/per ...
- Hibernate中的inverse和cascade属性
Hibernate中的inverse和cascade属性 inverse的值有两种,"true"和"false".inverse="false&quo ...
- 写给技术lead的招聘指南
工作这么久,面试过的工程师不下两三百人.大部份招到的人都比靠谱当然也有失败的例子.把亲身经历总结如下: 1. 什么人一定不能招: 理解能力差: 对你提出的问题,答不对题,重复提问.面试官可以在面试当中 ...
- leetcode_935. Knight Dialer_动态规划_矩阵快速幂
https://leetcode.com/problems/knight-dialer/ 在如下图的拨号键盘上,初始在键盘中任意位置,按照国际象棋中骑士(中国象棋中马)的走法走N-1步,能拨出多少种不 ...