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;
    }
  • 相关阅读:
    OpenWrt配置绿联的usb转Ethernet网口驱动
    SQL_wm_concat函数实验:实现字段合并
    BingMap频繁Add Pushpin和Delete Pushpin会导致内存泄露
    比較C++和Java 二
    【JAVASE】Java同一时候抛出多个异常
    uva 1463
    Android 撕衣服(刮刮乐游戏)
    轻松掌握一致性哈希算法
    Oracle之sql语句优化
    Eclipse导出Library
  • 原文地址:https://www.cnblogs.com/llei1573/p/3228725.html
Copyright © 2011-2022 走看看