码迷,mamicode.com
首页 > 其他好文 > 详细

J - 二分 POJ - 1905

时间:2020-01-13 23:34:01      阅读:87      评论:0      收藏:0      [点我收藏+]

标签:process   for循环   ace   tps   aced   math   initial   return   plain   

J - 二分

POJ - 1905

When a thin rod of length L is heated n degrees, it expands to a new length L‘=(1+nC)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

 

题目描述:

杆子加热会变长,由于左右有板子会拱起来。求正中间拱起的高度。

分析:

画出图,设圆心角为2a,找出几何关系。由二分找答案。

如我找出的关系:a/sin(a)=1+nxc,目标是q=tan(a/2)/2xl。

只要求出二分求出a就能得到答案q。

本来想用关系while(a/sin(a)!=(1+nxc))。因为精度较大会超时,改用for循环10000次,大概能达到答案。

代码:

#include<stdio.h>
#include<math.h> 
const double pi=acos(-1.0);
int main()
{
    double L,N;
    double C;
    while(1){
        scanf("%lf%lf%lf",&L,&N,&C);
        if(L==-1||N==-1||C==-1) break;
        double y=(1+N*C);
        double d;
        double l,r;
        
        l=0;
        r=pi/2;
        d=(l+r)/2;      
        int c=0;
        //while(d/sin(d)!=y)
        for(int i=0;i<100000;i++)
        {
            if(y>d/sin(d))
            {
                l=d;
            }
            else
            {
                r=d;
            }
            d=(l+r)/2;
        }
        double res=L*tan(d/2)/2;
        printf("%.3f\n",res);
    }
    return 0;
}

J - 二分 POJ - 1905

标签:process   for循环   ace   tps   aced   math   initial   return   plain   

原文地址:https://www.cnblogs.com/studyshare777/p/12189664.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!