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),感知机是线性分类器,他的目标就是通过寻找超平面实现对样本的分类:对于二维世界,就是找到一条线,三维世界就是找到一个面,多维世界就是要 ...
随机推荐
- Springboot的yml文件
spring: datasource: # 数据库四大组件 schema-password: root data-username: root driver-class-name: com.mysql ...
- byte的范围-128-127
01111111 表示的是最大的数字 是127这个没有问题 ,前面的0 表示的正数,1表示的负数 而负数在计算机中的存储都是通过补码的形式存在的,也就是说 1 1111 111 是计算机中最小的数 ...
- AIDL(1):简介
Android 接口定义语言 (AIDL) 1.AIDL是什么 AIDL(Android 接口定义语言)与您可能使用过的其他 IDL 类似. 您可以利用它定义客户端与服务使用进程间通信 (IPC) 进 ...
- (028)[技术资料]et99加密狗打开函数的一个小bug
et99加密狗的打开函数,其官方vb调用申明如下:Declare Function et_OpenToken Lib "FT_ET99_API.dll" (ByRef et99ha ...
- Hash环/一致性Hash原理
当前,Memcached.Redis这类分布式kv缓存已经非常普遍.从本篇开始,本系列将分析分布式缓存相关的原理.使用策略和最佳实践. 我们知道Memcached的分布式其实是一种“伪分布式”,也就是 ...
- php服务端接收post的json数据
最近用到ext与PHP交互,ext把json数据post给PHP,但在PHP里面$_post获取不到,$_REQUEST也获取不到,但是通过firedebug看到的请求信息确实是把JSON数据post ...
- poj3252Round Numbers
链接 也算是组合 以前按组合做过一次 忘记怎么做的了 这次按dp写的 dp[i][j][g][k] 表示第i位为k(0|1)而且有j个1,g个0的情况数 貌似写的麻烦了...这一类的题,进行逐位计算就 ...
- postman断言分析
最近测试中用到postman,使用后就简单总结下常用的断言,下面带图的自己最常用的,其他的没怎么用. postman断言是JavaScript语言编写的,在postman客户端指定区域编写即可. 断言 ...
- android开发学习 ------- 【转】EventBus的学习理解
EventBus是一个Android端优化的publish/subscribe消息总线,简化了应用程序内各组件间.组件与后台线程间的通信. 比如请求网络,等网络返回时通过Handler或Broadca ...
- 初识node,原理与浏览器何其相似
话不多说,直接上图. 今日入手开始学习Nodejs,加油吧,小小前端的大V梦ヾ(◍°∇°◍)ノ゙