POJ 1905-Expanding Rods(二分法+计算几何)

题目地址:POJ 1905

题意:一根某种材料做的直杆被夹在两面墙之间,当他受热时长度变长,就会因两面墙的挤压而向上隆起。长度变化函数为 L'=(1+n*C)*L,给定L,C,n,求向上拱起的高度H。

思路:

手动计算出这两个公式,然后用二分查找h值。

#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <map>
using namespace std;
typedef long long LL;
const int inf=0x3f3f3f3f;
const double pi= acos(-1.0);
const double esp=1e-8;
int main()
{
    double L,N,C;
    double s,h,r;
    double low,high,mid,ans;
    while(~scanf("%lf %lf %lf",&L,&N,&C)){
        if(L==-1&&N==-1&&C==-1) break;
        low=0;
        high=0.5*L;
        s=(1+N*C)*L;
        while(high-low>esp){
            mid=(low+high)*0.5;
            r=(4*mid*mid+L*L)/(8*mid);
            if(2*r*asin(L/(2*r))<s){
                low=mid;
            }
            else
                high=mid;
        }
        printf("%.3lf\n",mid);
    }
    return 0;
}


posted @ 2015-06-07 17:18  hrhguanli  阅读(190)  评论(0编辑  收藏  举报