poj 1905 Expanding Rods (數學 計算方法 二分)

來源:互聯網
上載者:User

標籤:style   blog   http   color   os   io   re   c   

題目連結

題意:將長度為L的棒子卡在牆壁之間。現在因為某種原因,木棒變長了,因為還在牆壁之間,所以彎成了一個弧度,現在求的是弧的最高處與木棒原先的地方的最大距離。

分析:

下面的分析是網上別人的分析:

設弦長為L0(即原長),弧長為L1=(1+n*C)*l0,目標值為h,半徑為R,弧所對圓心角為2θ(弧度制)。
可以得到以下方程組:
圓的弧長公式:L1=2θR
三角函數公式:L0=2*R*sinθ,變換得θ=arcsin(L0/(2*R))
勾股定理:R^2=(R-h)^2+(0.5*L0)^2,變換得L0^2+4*h^2=8*h*R
合并①②式得到
L1=2*R*arcsin(L0/(2*R))
半徑R可以由③式變換得到
R=(L0^2+4*h^2)/(8*h)
可以用二分枚舉h的值,計算出R和L1,與題目中L1進行比較。

 1 #include <iostream> 2 #include <cstring> 3 #include <cstdlib> 4 #include <cmath> 5 #include <cstdio> 6 #include <vector> 7 #include <algorithm> 8 #define LL long long 9 using namespace std;10 const double eps = 1e-8;11 12 int main()13 {14     double l0, n, c, l1, l2, r;15     double high, low, mid;16     while(cin>>l0>>n>>c)17     {18         if(l0==-1&&n==-1&&c==-1) break;19         l1 = (1+n*c)*l0;20         low = 0; high = 0.5*l0;21         while(high-low>eps)22         {23             mid = (low+high)/2;24             r = (l0*l0 + 4*mid*mid)/(8*mid);25             l2 = 2*r*asin(l0/(2*r));26             if(l1 < l2) high = mid;27             else low = mid;28         }29         mid = (low+high)/2;30         printf("%.3lf\n", mid);31     }32     return 0;33 }

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.