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.
When a thin rod is mounted on two solid walls and then heated, it
expands and takes the shape of a circular segment, the original rod
being the chord of the segment.

Your task is to compute the distance by which the center of the rod is displaced.

Input

The
input contains multiple lines. Each line of input contains three
non-negative numbers: the initial lenth of the rod in millimeters, the
temperature change in degrees and the coefficient of heat expansion of
the material. Input data guarantee that no rod expands by more than one
half of its original length. The last line of input contains three
negative numbers and it should not be processed.

Output

For
each line of input, output one line with the displacement of the center
of the rod in millimeters with 3 digits of precision.

Sample Input

1000 100 0.0001
15000 10 0.00006
10 0 0.001
-1 -1 -1

Sample Output

61.329
225.020
0.000

题目:可以这样理解,给你一根木杆,夹在某物体之间。现在木杆会受热膨胀,膨胀增长,在两端物体的挤压下就会变弯曲,如上图所示。从一根直的木杆变到弯曲的木杆,两种状态下,木杆中间位置的高度差是多少?解法全在上面的图片中!

代码:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <math.h>
#include <iostream>
#include <string>
#include <stack>
#include <algorithm>
#define eps 1e-5

using namespace std;

int main()
{
    // L‘=(1+n*C)*L
    double L, n, c;
    while(scanf("%lf %lf %lf", &L, &n, &c)!=EOF)
    {
        if(L<0 && n<0 && c<0) break;
        double low=0.0;
        double high=0.5*L;
        double mid;
        double s=(1.0+n*c)*L;
        double R;

        while(high-low>eps){
            mid=(low+high)/2.0;
            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-10-10 03:14:14

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

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

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,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

POJ 2391 Ombrophobic Bovines 不喜欢雨的奶牛 Floyd+二分枚举+最大流

题目链接:POJ 2391 Ombrophobic Bovines Ombrophobic Bovines Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 15006   Accepted: 3278 Description FJ's cows really hate getting wet so much that the mere thought of getting caught in the rain makes

POJ 1905(expanding rods)

[题意描述] 本题就是给定一个圆棒的热膨胀系数以及膨胀的温度,求最后变弯后中心点与原来中心点的距离. [思路分析] 几何+二分: 根据公式我们就可以利用二分进行查找了,当然二分是有技巧的,我们由于是double型数据,我们需要在设置循环条件时不能用high-low>0(会陷入系循环)而是需要设置精度esp(1e-5)写成high-low>esp就可以了. [AC代码] #include<iostream> #include<math.h> #include<iom