POJ 1905(expanding rods)

【题意描述】

本题就是给定一个圆棒的热膨胀系数以及膨胀的温度,求最后变弯后中心点与原来中心点的距离。

【思路分析】

几何+二分:

根据公式我们就可以利用二分进行查找了,当然二分是有技巧的,我们由于是double型数据,我们需要在设置循环条件时不能用high-low>0(会陷入系循环)而是需要设置精度esp(1e-5)写成high-low>esp就可以了。

【AC代码】

#include<iostream>
#include<math.h>
#include<iomanip>
using namespace std;
#define esp  1e-7
int main()
{
 double l,d,c;
 while(cin>>l>>d>>c)
 {
     if(l<0&&d<0&&c<0)
        break;
     if(l==0||c==0||d==0)
        cout<<"0.000"<<endl;
     else
     {
        double high=l*0.5;
        double low=0.0;
        double s=(1+d*c)*l;
        double mid;
        while(high-low>esp)
        {
             mid=(high+low)/2;
            double  r=(4*mid*mid+l*l)/(8*mid);
            double  s1=2*r*asin(l/(2*r));
            if(s1<s) low=mid;
            else high=mid;
        }
        double h=mid;
        cout<<fixed<<setprecision(3)<<h<<endl;
     }
 }
 return 0;
}

POJ 1905(expanding rods)

时间: 2024-08-29 02:15:08

POJ 1905(expanding rods)的相关文章

POJ 1905(集训比赛2B_A题)解题报告

题目链接:http://poj.org/problem?id=1905 --------------------------------------------------------- 题意:一个线段,给出长度.加热温度及热膨胀系数,线段加热后变为圆弧的一部分,要求求弧顶长度为多少. 思路:简单的画一下图,发现几何关系还是比较明确的,但是发现x的数学表达式并不容易解出来,所以采用二分法求值的方法.选择二分的对象很重要,直接选择对要求的x进行二分,避免角度误差太大. 代码: #include <

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

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 (二分+计算几何+精度处理)

题目地址: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(木杆的膨胀)【数学计算+二分枚举】

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

UVA 10668 - Expanding Rods(数学+二分)

UVA 10668 - Expanding Rods 题目链接 题意:给定一个铁棒,如图中加热会变成一段圆弧,长度为L′=(1+nc)l,问这时和原来位置的高度之差 思路:画一下图可以很容易推出公式,设圆弧扇形部弧度r,那么可以计算出铁棒长度为lr/sin(r)这个公式在[0, pi/2]是单调递增的,所以可以用二分法去求解 要注意的一点是最后答案计算过程中带入mid,之前是带入x(二分的左边值),可实际上x是可能等于0的,而带入mid,由于是double型,所以mid实际上表示是一个非常趋近0

poj 1905 (二分查找)

链接:poj 1905 截取自某大牛的blog,详情请关注:链接:Enumz 题意:一根两端固定在两面墙上的杆长度为L,受热弯曲后变弯曲, 长度L′=(1+nc)*L,求前后两个状态的杆的中点位置的距离 分析:设L′对应的半径为r,弧长为2α,要求的距离为x 根据直角三角形的性质可得: 根据弧长公式L′=2αr可得 有勾股定理得出: 代入得: 其为单调函数,二分求解即可. PS:卡精度 特判若输入存在0,则直接输出0.000 #include<stdio.h> #include<math