前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >POJ 1905 Expanding Rods(二分)

POJ 1905 Expanding Rods(二分)

作者头像
风骨散人Chiam
发布2020-10-28 10:34:01
2670
发布2020-10-28 10:34:01
举报
文章被收录于专栏:CSDN旧文

Expanding Rods Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 20224 Accepted: 5412 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 Source

Waterloo local 2004.06.12

二分,看到网上都是asin acos 做的,其实只要有一个关系式,就能进行二分,二分是一种思想,别要人云亦云。

代码语言:javascript
复制
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
#define esp 1e-8
int main()
{
	double len,c,lv,h,up,lo,r;
	while(scanf("%lf%lf%lf",&len,&c,&lv)==3&&!(len==-1))
	{
        double len2=(1+c*lv)*len;
            up=len/2.0;
            lo=0.0;
	    while(up-lo>esp){
            h=(up+lo)/2.0;
             r=(len*len+4*h*h)/8/h;
     //       cout<<len2/2.0/r<<"  "<<asin(len/2.0/r)<<"   "<<up<<"  "<<lo<<"  "<<h<<endl;
            if((len2/2.0/r)>asin(len/2.0/r)) lo=h;
            else up=h;
        }
        printf("%.3f\n",h);
	}
	return 0;
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019/05/18 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档