POJ 1905 Expanding Rods#二分

http://poj.org/problem?id=1905

题意:将一条直线变成一条弧线(该弧线是圆的一部分),求中心位置发生的位移。

由于精度需要控制好,所以选择用圆半径作为二分的目标,l=0,r=INF,LL为弧线长度,根据半径mid以及弦长L,可以求出对应的弧线长度t=2*asin(0.5*L/mid)*mid,再与LL比较,若t<LL,说明半径取大了,故r=mid,继续二分。

#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
#define INF 10e8

int main()
{
    double L,n,C;
    while(~scanf("%lf%lf%lf",&L,&n,&C))
    {
        if(L==-1&&n==-1&&C==-1)
            break;
        if(n*C<0.000001)
        {
            printf("0.000\n");
            continue;
        }
        double LL=(1+n*C)*L;
        double mid,l=0,r=INF,t;
        while(l+1e-6<r)
        {
            mid=(l+r)/2;
            t=2*asin(0.5*L/mid)*mid;
            if(t<LL)
                r=mid;
            else l=mid;
        }
        double ans=mid-sqrt(mid*mid-(L*L)/4);
        printf("%.3lf\n",ans);
    }
    return 0;
}
时间: 2024-12-21 07:59:39

POJ 1905 Expanding Rods#二分的相关文章

POJ 1905 Expanding Rods (二分+计算几何+精度处理)

题目地址:POJ 1905 用二分枚举h,然后判断弧长是否符合条件.重点还是在精度问题上,具体看代码吧.. #include <iostream> #include <string.h> #include <math.h> #include <queue> #include <algorithm> #include <stdlib.h> #include <map> #include <set> #includ

poj 1905 Expanding Rods (数学 计算方法 二分)

题目链接 题意:将长度为L的棒子卡在墙壁之间.现在因为某种原因,木棒变长了,因为还在墙壁之间,所以弯成了一个弧度,现在求的是弧的最高处与木棒原先的地方的最大距离. 分析: 下面的分析是网上别人的分析: 设弦长为L0(即原长),弧长为L1=(1+n*C)*l0,目标值为h,半径为R,弧所对圆心角为2θ(弧度制).可以得到以下方程组:圆的弧长公式:L1=2θR三角函数公式:L0=2*R*sinθ,变换得θ=arcsin(L0/(2*R))勾股定理:R^2=(R-h)^2+(0.5*L0)^2,变换得

POJ 1905 Expanding Rods 浮点数二分

Expanding Rods Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 11145   Accepted: 2879 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. Whe

poj 1905 Expanding Rods(木杆的膨胀)【数学计算+二分枚举】

Expanding Rods Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 13516   Accepted: 3484 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. Whe

POJ 1905 Expanding Rods

Expanding Rods Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 12796   Accepted: 3299 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. Whe

poj 1905 Expanding Rods 二分解方程

题意: 中已知L,S解h. 分析: 两个方程两个未知数,理论是可解的.解起来有困难,可用二分的方法. 代码: #include <iostream> #include <cmath> using namespace std; int main() { double l,n,c,s,r; while(scanf("%lf%lf%lf",&l,&n,&c)==3){ if(l<0) break; double mid,low=0.0,h

POJ 题目1905 Expanding Rods(二分,数学几何)

Expanding Rods Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 12827   Accepted: 3311 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. Whe

poj1905 Expanding Rods 二分

Expanding Rods Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 11782   Accepted: 3063 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. Whe

【POJ1905】Expanding Rods 二分答案+推公式

题意: 给出L,n,c,通过公式可以得到L'. 然后L是弦长,L'是弧长,从圆心向该弦做垂线,若长为d,求半径-d. 题解: 二分答案. 首先弧长通过圆心角和半径是可以计算的,那么我们可以二分答案(r-d). 然后有(r-mid)^2+(L/2)^2=r*r,通过这个可以O(1)算出r. 这样就可以通过 弧长=(圆心角/360°)*2πr计算出当前弧长进行check. 因为arcsin返回值为弧度,即(180/π)度,所以最后弧长公式是2*r*asin(L/(2*r)). 代码: #includ