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
  • 相关阅读:
    mySQL部分疑问和小结(orale)
    Java技术中的三大特性
    Java调用DB的存储过程
    Android Http异步请求,Callback
    android Handler的使用(一)
    Android之ContextMenu的使用方法以及与OptionMenu的区别(转)
    git 把文件从 版本管理中移除 andorid版本
    在GIT 中增加忽略文件夹与文件
    玩转Android---组件篇---Intent(意图)
    Android Activity和Intent机制学习笔记
  • 原文地址:https://www.cnblogs.com/lxm940130740/p/3642427.html
Copyright © 2011-2022 走看看