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;
}


转载于:https://www.cnblogs.com/hrhguanli/p/4558736.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值