POJ 1905--Expanding Rods

本文介绍了一种通过三角函数计算给定长度下增加高度的方法。利用sinc函数的特性,采用二分法逼近求解θ值,进而计算出特定条件下的增加高度。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

根据题意,设theta为弧对应角度的一半,则有等式:

  1. 增加的高度h = L*tan(theta/2)/2。
  2. sin(theta)/theta = 1/(1+n*c)。
2式中的sin(theta)/theta,即sinc(theta)是信号处理中常见的振荡函数,当theta在[0,pi/2]之间时此函数为单调递减函数,所以可以根据等式右边的值使用二分不断逼近正确的theta值。

#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
#define sinc(x)  sin(x)/(x)
#define precision  0.000000000001
#define pi 3.1415926535897932384626433832795028

double calc_theta(double y)
{
    double left = 0;
    double right = pi/2.0;
    double mid;
    while(left < right)
    {
        mid = (left+right)/2.0;
        if(sinc(mid) < y)               //sinc(x)在[0,pi/2]之间为单调递减函数
            right = mid-precision;
        else if(sinc(mid) > y)
            left = mid+precision;
        else
            return mid;
    }
    return left;
}

int main()
{
    double L;
    double degree;
    double c;
    double dest;
    double theta;
    while(scanf("%lf%lf%lf",&L,°ree,&c)&&(L != -1))
    {
        if(L == 0 || degree == 0 || c == 0)
            printf("0.000\n");
        else
        {
        dest = 1.0/(1+degree*c);
        theta = calc_theta(dest);
        printf("%.3f\n",L*tan(theta/2.0)/2.0);
        }
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值