Expanding Rods-二分

A - Expanding Rods

Time Limit:1000MS     Memory Limit:30000KB     64bit IO Format:%I64d
& %I64u

Submit Status Practice POJ
1905

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
/*
Author: 2486
Memory: 164 KB		Time: 0 MS
Language: C++		Result: Accepted
*/
//从边的角度思考
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
const double PI=3.1415926535898;
const double eps=1e-7;
double iL,t,c,Ls;
bool C(double m){
    double r=m+iL*iL/(4.0*m);
    return asin(iL/r)*r>=Ls;
}
int main(){
while(~scanf("%lf%lf%lf",&iL,&t,&c)){
    if(iL<0||t<0||c<0)break;
    Ls=(1.0+t*c)*iL;
    double lb=0,ub=iL/2.0;
    while(ub-lb>eps){
        double mid=(ub+lb)/2.0;
        if(C(mid)){
            ub=mid;
        }
        else lb=mid;
    }
    printf("%.3lf\n",ub);
}
return 0;
}

以上的是通过相似三角形的思维,m/(L/2)=(L/2)/(2R-m)

一下是通过角度a=L/R,所对应的角

/*
Author: 2486
Memory: 176 KB		Time: 0 MS
Language: C++		Result: Accepted
*/
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
//从角的角度思考
using namespace std;
const double PI=acos(-1.0);
const double eps=1e-15;
double iL,t,c,Ls;
bool C(double m){
    if(((iL/sin(m))/2)*m*2.0>=Ls)return true;
    return false;
}
int main(){
while(~scanf("%lf%lf%lf",&iL,&t,&c)){
    if(iL<0||t<0||c<0)break;
    Ls=(1.0+t*c)*iL;
    double lb=0,ub=PI/2.0;
    while(ub-lb>eps){
        double mid=(ub+lb)/2.0;
        if(C(mid)){
            ub=mid;
        }
        else lb=mid;
    }
    printf("%.3lf\n",(iL/2/sin(ub))-iL/2/tan(ub));
}

return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-10-30 10:30:35

Expanding Rods-二分的相关文章

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

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&

【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

POJ1905 expanding rods 【水二分+谜之WA】

一道很水的题,就是不知道为什么wa,,, 其实小优那个精度控制循环控制二分的方法不算好,如果esp太小,会TLE,直接人工控制次数最好了 #include <cstdio> #include <cmath> #include <iostream> using namespace std; double getres(double r,double s,double l) { //cout<<(r-s/acos(1-l*l/(2.0*r*r)))<<

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,变换得

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

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