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;
}
时间: 2024-11-09 08:28:31

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#二分

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&

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