zoukankan      html  css  js  c++  java
  • poj 1905 Expanding Rods

    Expanding Rods
    Time Limit: 1000MS   Memory Limit: 30000K
    Total Submissions: 9997   Accepted: 2531

    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
    

    Source

    //这图形应该是个扇形d==(1+n*C)*L,d就是它的弧长,我们可以对半径r二分
    //到时候根据勾股定理就可以求出h=sqrt(r*r-(l/2)*(l/2));
    //现在推下弧长与半径的公式,d=r*2*α(α为弧度);sinα=(d/2)/r   =>
    //   α=arcsin(d/(2*r));  ==>d=r*2*arcsin(d/(2*r));
    #include<stdio.h>
    #include<math.h>
    int main()
    {
         double l,n,c,d,left,r,mid;
         while(scanf("%lf %lf %lf",&l,&n,&c)!=EOF)
         {
              d=(1+n*c)*l;
              if(l==-1&&n==-1&&c==-1)
              break;
              if(d==l)
              {
                   printf("0.000
    ");
                   continue;
              }
              left=0.0,r=999999999;
              while(r-left>1e-6)//精度不要太大,不然会超时
              {
                   mid=(left+r)/2;
                   if(2*mid*asin(l/(2*mid))<d)//弧长比目标弧长小,半径就要变小,自己画个图就出来了
                    r=mid;
                   else
                   left=mid;
    
              }
              printf("%.3lf
    ",mid-sqrt(mid*mid-(l/2)*(l/2)));
         }
         return 0;
    }
  • 相关阅读:
    [转]采样和滤波
    "我的电脑"和所有文件夹打不开的解决办法
    巨无霸“火星”CPU散热器亮相
    [转]规范化编程:ANSI和UNICODE的使用
    2006第三季度:10大最糟科技事件
    【掉下巴】如此公路
    Windows CE 初体验 幻灯
    Windows CE.NET Core OS 特性详解(二)最终用户应用程序
    基于PB的Windows CE模拟环境的配置及调试
    非阻塞I/O
  • 原文地址:https://www.cnblogs.com/llei1573/p/3228725.html
Copyright © 2011-2022 走看看