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
  • 相关阅读:
    Linux 字典数组应用
    Linux shell 字符串切割 内置方法
    【Swing/文本组件】定义自动换行的文本域
    【C++语法基础】实验1
    【Swing程序设计/常用面板】
    【标签组件与图标 3.3】
    【2018.2.26算法总结#分治】
    数据结构#课表排序及查询
    数据结构#前序遍历建立二叉树 输出中序遍历
    OJ#1002 又是a+b
  • 原文地址:https://www.cnblogs.com/lxm940130740/p/3642427.html
Copyright © 2011-2022 走看看