zoukankan      html  css  js  c++  java
  • poj 1905 Expanding Rods (数学 计算方法 二分)

    题目链接

    题意:将长度为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
    ", mid);
    31     }
    32     return 0;
    33 }
  • 相关阅读:
    数列分段 II
    Best Cow Fences
    愤怒的牛
    linux 查看文件
    糖果传递
    BL刀片更换主板设置raid
    glance启停
    depot制作
    刀片服务器密码过期, console无法登录解决方案
    DP无法删除失效的多路径链路方法
  • 原文地址:https://www.cnblogs.com/bfshm/p/3868438.html
Copyright © 2011-2022 走看看