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. (8)Linux(客户端)和Windows(服务端)下socket通信实例

    Linux(客户端)和Windows(服务端)下socket通信实例: (1)首先是Windows做客户端,Linux做服务端的程序 Windows   Client端 #include <st ...

  2. WWDC2014代码和视频下载

    WWDC2014 sample code 地址 http://pan.baidu.com/s/1qWGznnY WWDC2014 videos 地址 https://github.com/liubin ...

  3. 2.Vue子组件给父组件通信

    子组件给父组件通信 如果子组件想要改变数据呢?这在vue中是不允许的,因为vue只允许单向数据传递,这时候我们可以通过触发事件来通知父组件改变数据,从而达到改变子组件数据的目的 子组件: <te ...

  4. HTML5和CSS3兼容清单

    1.CSS3 2.CSS3选择器 3.HTML5 4.HTML5 From  

  5. C++ Boost库的编译及使用

    https://www.jianshu.com/p/de1fda741beb https://www.cnblogs.com/weizhixiang/p/5804778.html Windows编译 ...

  6. 线性中继器 Linear Repeater

     线性中继器(Linear Repeater,缩写L-REP) 高速信号在传输介质上传递时,信号衰减和噪声会导致有效数据信号越来越弱.L-REP就是用来再生高速信号,通过使用同等化(Equalizat ...

  7. 004-windows(64位)下使用curl命令

    一.下载工具包:http://curl.haxx.se/download.html 二.使用 使用方式一:在curl.exe目录中使用 解压下载后的压缩文件,通过cmd命令进入到curl.exe所在的 ...

  8. 测开之路九十六:css进阶之元素显示和可见性

    元素显示效果:display 块级元素,会导致换行:p.div.h...内联元素,不会导致换行:span.strong... 修改属性 让span标签换行 让指定div不换行 元素可见性:visibi ...

  9. 通过git新增、更新代码内容到github

    github可用于个人用户托管公开项目,对于异地上传下载十分方便 1.  准备工作 2.  首次上传执行命令集合 3.  更新执行命令集合 4.  命令总结 1.准备工作 a.注册github帐号 , ...

  10. JDK+Tomcat+Eclipse环境搭建过程记录

    这学期选了一门公选课叫网络开发工具与技术,主要学习用JSP语言构建网站.在配置环境的过程中遇到不少的坑,于是记录下来,希望能帮到大家. 系统环境:Win10 JDK版本:8u121, JAVA版本1. ...