Bridge

A suspension bridge suspends the roadway from huge main cables, which extend from one end of the bridge to the other. These cables rest on top of high towers and are secured at each end by anchorages. The towers enable the main cables to be draped over long distances.

Suppose that the maximum distance between two neighboring towers is D <tex2html_verbatim_mark>, and that the distance from the top of a tower to the roadway is H <tex2html_verbatim_mark>. Also suppose that the shape of a cable between any two neighboring towers is the same symmetric parabola (as shown in the figure). Now given B <tex2html_verbatim_mark>, the length of the bridge and L <tex2html_verbatim_mark>, the total length of the cables, you are asked to calculate the distance between the roadway and the lowest point of the cable, with minimum number of towers built (Assume that there are always two towers built at the two ends of a bridge).

<tex2html_verbatim_mark>

Input

Standard input will contain multiple test cases. The first line of the input is a single integer T <tex2html_verbatim_mark>(1T10) <tex2html_verbatim_mark>which is the number of test cases. T <tex2html_verbatim_mark>test cases follow, each preceded by a single blank line.

For each test case, 4 positive integers are given on a single line.

D<tex2html_verbatim_mark>
- the maximum distance between two neighboring towers;
H<tex2html_verbatim_mark>
- the distance from the top of a tower to the roadway;
B<tex2html_verbatim_mark>
- the length of the bridge; and
L<tex2html_verbatim_mark>
- the total length of the cables.

It is guaranteed that BL <tex2html_verbatim_mark>. The cable will always be above the roadway.

Output

Results should be directed to standard output. Start each case with "Case # <tex2html_verbatim_mark>:" on a single line, where # <tex2html_verbatim_mark>is the case number starting from 1. Two consecutive cases should be separated by a single blank line. No blank line should be produced after the last test case.

For each test case, print the distance between the roadway and the lowest point of the cable, as is described in the problem. The value must be accurate up to two decimal places.

Sample Input

2

20 101 400 4042

1 2 3 4

Sample Output

Case 1:
1.00 Case 2:
1.60
 //总算遇到精度问题啦,吃一堑长一智了!!!

 #include<stdio.h>
#include<math.h>
#define eps 1e-10//这题居然卡精度的啊!!!!!哭死啦!!!!1e-8都过不了啊!!! int dcmp(double a)
{
if(fabs(a)<eps)return ;
if(a>)return ;
else return -;
} int main()
{
int ca,T,i,j;
int cnt,B,D,H,L;
scanf("%d",&T);
for(ca=;ca<=T;ca++)
{
double mid,d,l;
scanf("%d%d%d%d",&D,&H,&B,&L);
cnt=B/D;
if(cnt*D!=B)
cnt++;
d=1.0*B/cnt/2.0;
l=1.0*L/cnt/2.0;
double ll,rr;
ll=0.0,rr=1000000.0;
while(rr-ll>eps)
{
mid=(ll+rr)/2.0;
double tmp=sqrt(+1.0/4.0/mid/mid/d/d);
double sss=mid*d*d*tmp+1.0/4.0/mid*(log(*mid*d*(tmp+)));
if(dcmp(sss-l)==)
rr=mid-eps;
else
ll=mid+eps;
}
double k=mid;
double y=k*d*d;
double ans=1.0*H-y;
if(ans<)ans=;//可有可无,数据中的绳子都是伸直的!!
printf("Case %d:\n",ca);
printf("%.2f\n",ans);
if(ca<T)printf("\n");
}
}

UVAlive 3485 Bridge(抛物线弧长积分)的更多相关文章

  1. UVA 3485 Bridge

    题目大意 你的任务是修建一座大桥.桥上等距地摆放着若干个塔,塔高为H,宽度忽略不计.相邻两座塔之间的距离不能超过D.塔之间的绳索形成全等的对称抛物线.桥长度为B,绳索总长为L,如下图所示求建最少的塔时 ...

  2. HDU 4752 Polygon(抛物线长度积分)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4752 题意:给出一个抛物线和一个简单多边形.求抛物线在多边形内部的长度. 思路:首先求出多边形所有边和 ...

  3. LA 3485 Bridge

    自适应辛普森公式模板. #include<algorithm> #include<iostream> #include<cstring> #include<c ...

  4. LA 3485 (积分 辛普森自适应法) Bridge

    桥的间隔数为n = ceil(B/D),每段绳子的长度为L / n,相邻两塔之间的距离为 B / n 主要问题还是在于已知抛物线的开口宽度w 和 抛物线的高度h 求抛物线的长度 弧长积分公式为: 设抛 ...

  5. 曲线参数化的Javascript实现(代码篇)

    在曲线参数化的Javascript实现(理论篇)中推出了曲线弧长积分的公式,以及用二分法通过弧长s来查找样条曲线上对应的u,再求Q(u)的值.弧长积分函数如下: ,其中-----公式1 Simpson ...

  6. .Uva&LA部分题目代码

    1.LA 5694 Adding New Machine 关键词:数据结构,线段树,扫描线(FIFO) #include <algorithm> #include <cstdio&g ...

  7. uva 1356 Bridge ( 辛普森积分 )

    uva 1356 Bridge ( 辛普森积分 ) 不要问我辛普森怎么来的,其实我也不知道... #include<stdio.h> #include<math.h> #inc ...

  8. HDU_1071——积分求面积,抛物线顶点公式

    Problem Description Ignatius bought a land last week, but he didn't know the area of the land becaus ...

  9. UVA 1356 - Bridge(自适应辛普森)

    UVA 1356 - Bridge option=com_onlinejudge&Itemid=8&page=show_problem&category=493&pro ...

随机推荐

  1. router-link传递参数并获取

    跳转链接: <router-link :to="{path:'libraryDetail/', query:{library_id:data.library_id}}"> ...

  2. 我的"开发工具箱"

    我使用的IDEA插件 Free Mybatis plugin Alibaba Java Coding Guidelines 我的IDEA开发配置 配置Maven Runner -DarchetypeC ...

  3. 认识了一个新的手机游戏剖析工具- SnapDragon Profiler

    原来这个是高通的工具,具说UNITY官方推荐了这个工具.大概看了下,可以从宏观上实时剖析手机应用的方方面面

  4. Linux添加目录到环境变量以及添加Sublime Text到环境变量

    本文主要介绍了Linux添加目录到环境变量以及添加Sublime Text到环境变量,通过具体的解释说明,让我们从中学到Linux添加目录到环境变量以及添加Sublime Text到环境变量的精髓所在 ...

  5. 圆角Panel

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Diagnostic ...

  6. 像计算机科学家一样思考python-第4章 案例研究:接口设计

    系统环境 ubuntu18 4.1turtle模块 模块一开始导入turtle模块就报错了 Python ( , ::) [GCC ] on linux Type "help", ...

  7. tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance

    在执行自动化打包的时候报错,检查发现是Xcode的路径被改了 标记3的地方原来默认是没有内容的,点击它,然后会自动弹出一个选项,就是xcode的版本. 修改后,在命令行输入xcodebuild命令测试 ...

  8. spring监听机制——观察者模式的应用

    使用方法 spring监听模式需要三个组件: 1. 事件,需要继承ApplicationEvent,即观察者模式中的"主题",可以看做一个普通的bean类,用于保存在事件监听器的业 ...

  9. 阶段1 语言基础+高级_1-3-Java语言高级_06-File类与IO流_04 IO字节流_1_IO概述(概念&分类)

  10. ensorflow学习笔记四:mnist实例--用简单的神经网络来训练和测试

    http://www.cnblogs.com/denny402/p/5852983.html ensorflow学习笔记四:mnist实例--用简单的神经网络来训练和测试   刚开始学习tf时,我们从 ...