標籤: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 }