UVAlive 3485 Bridge(抛物线弧长积分)
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>(1
T
10) <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 B
L <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(抛物线弧长积分)的更多相关文章
- UVA 3485 Bridge
题目大意 你的任务是修建一座大桥.桥上等距地摆放着若干个塔,塔高为H,宽度忽略不计.相邻两座塔之间的距离不能超过D.塔之间的绳索形成全等的对称抛物线.桥长度为B,绳索总长为L,如下图所示求建最少的塔时 ...
- HDU 4752 Polygon(抛物线长度积分)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4752 题意:给出一个抛物线和一个简单多边形.求抛物线在多边形内部的长度. 思路:首先求出多边形所有边和 ...
- LA 3485 Bridge
自适应辛普森公式模板. #include<algorithm> #include<iostream> #include<cstring> #include<c ...
- LA 3485 (积分 辛普森自适应法) Bridge
桥的间隔数为n = ceil(B/D),每段绳子的长度为L / n,相邻两塔之间的距离为 B / n 主要问题还是在于已知抛物线的开口宽度w 和 抛物线的高度h 求抛物线的长度 弧长积分公式为: 设抛 ...
- 曲线参数化的Javascript实现(代码篇)
在曲线参数化的Javascript实现(理论篇)中推出了曲线弧长积分的公式,以及用二分法通过弧长s来查找样条曲线上对应的u,再求Q(u)的值.弧长积分函数如下: ,其中-----公式1 Simpson ...
- .Uva&LA部分题目代码
1.LA 5694 Adding New Machine 关键词:数据结构,线段树,扫描线(FIFO) #include <algorithm> #include <cstdio&g ...
- uva 1356 Bridge ( 辛普森积分 )
uva 1356 Bridge ( 辛普森积分 ) 不要问我辛普森怎么来的,其实我也不知道... #include<stdio.h> #include<math.h> #inc ...
- HDU_1071——积分求面积,抛物线顶点公式
Problem Description Ignatius bought a land last week, but he didn't know the area of the land becaus ...
- UVA 1356 - Bridge(自适应辛普森)
UVA 1356 - Bridge option=com_onlinejudge&Itemid=8&page=show_problem&category=493&pro ...
随机推荐
- assert出问题了?
刚学习Objective-C那会儿,还不太了解这个世界的惯用法,所以有些地方使用了C/C++的方式,虽然后来做过一定的修改, 但是项目中还是遗留了一些无关紧要的C/C++代码.比如对断言的运用. as ...
- 2018-2019-2 20175214 实验四《Android程序设计》实验报告
实验四<Android程序设计>实验报告 一.前期准备 安装Android Studio 参考http://www.cnblogs.com/rocedu/p/6371315.html#SE ...
- dd备份命令使用
转载——dd 参数解释 1. if=文件名:输入文件名,缺省为标准输入.即指定源文件.< if=input file > 2. of=文件名:输出文件名,缺省为标准输出.即指定目的文件.& ...
- Golang闭包的坑
team leader 发现一个Golang程序的bug,是由不正确使用闭包引起.记载一下,以作备忘. 猜猜一下程序的结果: import ( "fmt" "time&q ...
- 编程字体Source Code Pro 免费下载
对于程序员来说,好的字体应该满足的基本条件: 字母和数字易于分辨,如: 英文字母o 和 阿拉伯数字 0 ,或者 英文字母 l 和 阿拉伯数字 1 ,两个单引号 '' 和双引号 ”. 字体等宽,保持对齐 ...
- TensorFlow学习笔记12-word2vec模型
为什么学习word2word2vec模型? 该模型用来学习文字的向量表示.图像和音频可以直接处理原始像素点和音频中功率谱密度的强度值, 把它们直接编码成向量数据集.但在"自然语言处理&quo ...
- Spring MVC配置文件
都说开发Spring Web程序的配置文件很繁琐,所以就写了一篇配置博客, 首先是pom.xml文件 <project xmlns="http://maven.apache.org/P ...
- PAT甲级终结——心得总结
首先报喜一波 第一次考,满分,4道题总共花了2个小时做完,一部分是题简单的原因,一部分也是自己三刷了PAT的心血吧. 刷PAT的经验 神指导: 胡凡-<算法笔记> 神助攻:柳婼的博客,百度 ...
- javascript实现深浅拷贝
深浅拷贝通常是对于引用数据类型进行的(数据类型为:对象(Object).数组(Array).函数(Function)) 浅拷贝: let obj = {id: 1, name: 2}; let new ...
- oracle--事物特性、锁、
update emp set comm = 100 where empno = 7369; 使用dba用户查看事务 ADDR XIDUSN XIDSLOT XIDSQN UBAFIL UBABLK U ...