zoukankan      html  css  js  c++  java
  • poj1905

    Expanding Rods
    Time Limit: 1000MS   Memory Limit: 30000K
    Total Submissions: 10901   Accepted: 2802

    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



    思路:采用对半径进行二分的思想


     1 #include<iostream>
     2 #include<stdio.h>
     3 #include<string.h>
     4 #include<math.h>
     5 #define M 0xfffffff
     6 using namespace std;
     7 int main()
     8 {
     9     double n,L,L1,c;
    10     while(scanf("%lf%lf%lf",&L,&n,&c)!=EOF)
    11     {
    12         if(L<0)
    13         break;
    14         if(n*c<0.000001)//此种情况不能构成圆形
    15         {
    16             printf("0.000
    ");
    17             continue;
    18         }
    19         L1=(1+n*c)*L;
    20         double low=0,high=M,mid;
    21         while(high-low>0.000001)
    22         {
    23             mid=(high+low)/2;
    24             double angle=asin(0.5*L/mid);
    25             if(2*angle*mid<L1)
    26             high=mid;
    27             else
    28             low=mid;
    29         }
    30         printf("%.3lf
    ",mid-sqrt(mid*mid-0.5*L*0.5*L));
    31     }
    32     return 0;
    33 }
    View Code
  • 相关阅读:
    C#发送邮件的实现实例解析
    抄录一下别人的经验
    centos学习一
    关于百度地图API批量转换成坐标的方法
    js和PHP等脚本语言for循环和if语句里面定义变量的作用域
    关于js中去取数组中的重复字符串
    关于handler返回的数据处理
    通过定义任务委托的方法处理 action
    关于点击按钮图片左右切换的随笔
    关于网站内容分享到新浪微博等的代码
  • 原文地址:https://www.cnblogs.com/lxm940130740/p/3642427.html
Copyright © 2011-2022 走看看