zoukankan      html  css  js  c++  java
  • Expanding Rods 二分查找(精度很重要)

    Problem Description
    When a thin rod of length L is heated n degrees, it expands to a new length L'=(1+n*C)*L, where C is the coefficient of heat expansion. 
    When a thin rod is mounted on two solid walls and then heated, it expands and takes the shape of a circular segment, the original rod being the chord of the segment. 

    Your task is to compute the distance by which the center of the rod is displaced. 
     

    Input
    The input contains multiple lines. Each line of input contains three non-negative numbers: the initial lenth of the rod in millimeters, the temperature change in degrees and the coefficient of heat expansion of the material. Input data guarantee that no rod expands by more than one half of its original length. The last line of input contains three negative numbers and it should not be processed.
     

    Output
    For each line of input, output one line with the displacement of the center of the rod in millimeters with 3 digits of precision. 
     

    Sample Input
    1000 100 0.0001 15000 10 0.00006 10 0 0.001 -1 -1 -1
     

    Sample Output
    61.329 225.020 0.000
    **************************************************************************************************************************
    有数学公式:弧长L=R*a(角度);设弦长为L0,则sin(a/2)=(L0/2)/R;则(a/2)=asin((L0/2)/R);则a=2*asin((L0/2)/R);
    **************************************************************************************************************************
     1 #include<iostream>
     2 #include<string>
     3 #include<cstring>
     4 #include<cmath>
     5 #include<cstdio>
     6 #include<queue>
     7 //#define  PI  3.1415926535897932
     8 using namespace std;
     9 double esp=1e-6;
    10 double L0,L1,n,c,L2,mid,r;
    11 double  high,low;
    12 int main()
    13 {
    14     while(scanf("%lf%lf%lf",&L0,&n,&c)&&L0>=0&&n>=0&&c>=0)
    15     {
    16         L1=(1+n*c)*L0;
    17         //printf("L0:%lf    L1:%lf
    ",L0,L1);
    18         high=0.5*L0;
    19         low=0.0;
    20         while(high-low>esp)
    21         {
    22             mid=(high+low)/2;
    23             r=(L0*L0+4*mid*mid)/(8*mid);
    24             L2=2*r*asin(L0/(2*r));
    25             if(L2<=L1)low=mid;
    26              else
    27                high=mid;
    28         }
    29         mid=(high+low)/2;
    30         printf("%.3lf
    ",mid);
    31     }
    32     return 0;
    33 }
    View Code

  • 相关阅读:
    MySQL+Toad for Mysql安装,配置及导入中文数据解决乱码等问题
    Excel日期格式提取year
    arcgis中使用excel中x,y坐标创建点问题
    GIS中栅格数据的拼接
    R 中安装xlsx包缺少java环境解决方案
    R中统计量的中英文解释
    arcgis离海距离的计算
    EXCEL处理数据小技巧
    nginx部署成功却没有办法访问
    Linux安装yum install gcc-c++出错:Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=stock error was 14: curl#6
  • 原文地址:https://www.cnblogs.com/sdau--codeants/p/3377895.html
Copyright © 2011-2022 走看看