poj 1905 (Expanding Rods) 二分的运用

Expanding Rods
Time Limit: 1000MS Memory Limit: 30000K
Total Submissions: 15096 Accepted: 4009

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
之前只知道二分能解决整数的问题,这道题用二分卡精度
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>

using namespace std;

const double ex=1e-5;       //que保精度
int main()
{
    double l,n,c;
    while(~scanf("%lf%lf%lf",&l,&n,&c))
    {
         if(l==-1&&n==-1&&c==-1)break;
         if(l==0||n==0||c==0)                 //当输入存在一个0时,就可以输出0.000;
         {
             printf("0.000\n");
             continue;
         }
         double L=(1+n*c)*l;           //变化后的长度
         double s=0,e=L*0.5;          //下界,上界
         double d=0.5*l;                 
         double mid;
         double x;
         while(1)
         {
			if(e-s<ex)break;
            mid=(s+e)/2;
			double ll=2*atan(2*mid*d/(d*d-mid*mid))*(mid*mid+d*d)/(2*mid);       //由已知条件推出的公式
			if(ll<L)s=mid;
			else e=mid;

         }
        double h=mid;
         printf("%.3f\n",h);
    }
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值