LA 3458——Bridge
生活随笔
收集整理的這篇文章主要介紹了
LA 3458——Bridge
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
題意:
建設一座大橋,在橋上建若干個塔,塔高為H,相鄰兩塔間的距離不能超過D,橋長度為B,線的總長度為L,橋之間的繩索為對稱拋物線,問建最少塔的時候的線索的最下端的離地高度y
思路:
仔細分析一下,不難發現,只要求得拋物線在y軸的長度h,那么所求即為H-h,而求解這一段實際上是求解一個函數f(D1,L1)=h的方程,其中D1為兩個塔間的間距,L1為該拋物線的曲線長度,這兩個量極易容易求出,而這又是一個關于拋物線的二次函數,所以很容易二分枚舉并積分來調整長度。
code:
#include <iostream> #include <cstdio> #include <algorithm> #include <cmath> using namespace std;double a; double F(double x){return sqrt(1+4*a*a*x*x); } double simpson(double a,double b){double c=a+(b-a)/2;return (F(a)+4*F(c)+F(b))*(b-a)/6; } double asr(double a,double b,double eps,double A){double c=a+(b-a)/2;double L=simpson(a,c),R=simpson(c,b);if (fabs(L+R-A)<=15*eps) return L+R+(L+R-A)/15;return asr(a,c,eps/2,L)+asr(c,b,eps/2,R); } double asr(double a,double b,double eps){return asr(a,b,eps,simpson(a,b)); } double asr_len(double w,double h){a=4.0*h/(w*w);return asr(0,w/2,1e-5)*2; } int main() {int T;scanf("%d",&T);for (int ca=1;ca<=T;ca++){double D,H,B,L;scanf("%lf%lf%lf%lf",&D,&H,&B,&L);int n=(B+D-1)/D;double D1=(double)B/n;double L1=(double)L/n;double x=0,y=H;while (y-x>1e-5){double m=x+(y-x)/2;if (asr_len(D1,m)<L1) x=m;else y=m;}if (ca>1) puts("");printf("Case %d:\n%.2f\n",ca,H-x);} }總結
以上是生活随笔為你收集整理的LA 3458——Bridge的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: HDU 5842—— Lweb and
- 下一篇: 清凌凌的水蓝莹莹的天剧情介绍