POJ 1905 Expanding Rods( 二分搜索 )


题意:一个钢棍在两面墙之间,它受热会膨胀成一个圆弧形物体,这个物体长 S = ( 1 + n * C ) * L,现在给出原长 L ,温度改变量 n ,和热膨胀系数 C,求膨胀后先后中点的高度差。

**思路:****戳这里 -> 小優YoU巨巨写的题解挺好的! **

balabala:
1. 关键还是得找到变量之间的关系
2. 输出格式需要注意使用 fixed + setprecision 可以避免输出科学计数法形式的值


/*************************************************************************
    > File Name: poj1905.cpp
    > Author:    WArobot 
    > Blog:      http://www.cnblogs.com/WArobot/ 
    > Created Time: 2017年05月05日 星期五 15时07分04秒
 ************************************************************************/

#include<iostream>
#include<cmath>
#include<cstdio>
#include<iomanip>
using namespace std;

#define eps 1e-5
double L,n,C,S;
bool check(double h){
	double r = (L*L+4*h*h)/(8*h);
	double t = asin(L/(2*r))*2*r;
	if(S>t)	return 1;		// 说明h偏小
	else	return 0;		// 说明h偏大
}
int main(){
	while(cin>>L>>n>>C){
		if(L==-1 && n==-1 && C==-1)	break;
		S = (1+n*C)*L;
		double l , r , mid;
		l = 0;	r = L/2;
		while(r-l>eps){
			mid = (r+l)/2;
			if(check(mid))	l = mid;
			else			r = mid;
		}
		double h = mid;
		// printf("%.3f\n",h);
		cout<<fixed<<setprecision(3)<<h<<endl;
	}
	return 0;
}
posted @ 2017-05-05 23:08  ojnQ  阅读(157)  评论(0编辑  收藏  举报