zoukankan      html  css  js  c++  java
  • Expanding Rods POJ 1905 二分

    Time Limit: 1000MS   Memory Limit: 30000K
    Total Submissions: 17050   Accepted: 4503

    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
    

    Source

    #include<iostream>
    #include<cstdio>
    #include<cmath>
    #include<cstring>
    #include<sstream>
    #include<algorithm>
    #include<queue>
    #include<deque>
    #include<iomanip>
    #include<vector>
    #include<cmath>
    #include<map>
    #include<stack>
    #include<set>
    #include<fstream>
    #include<memory>
    #include<list>
    #include<string>
    using namespace std;
    typedef long long LL;
    typedef unsigned long long ULL;
    #define MAXN 20009
    #define N 21
    #define MOD 1000000
    #define INF 1000000009
    const double eps = 1e-8;
    const double PI = acos(-1.0);
    /*
    给一个弦长和弧长 求圆心到弦的距离  直接求不太好求
    可以用二分搜索
    为了避免精度损失应该 尽量少用除法! 一开始想枚举弧度有点跑偏。。
    因为枚举弧度 :sgn(L*x - 2 * l*sin(x / 2)) == 0 这个表达式判断失败后不好分析下一步二分的范围
    还是直接枚举H h越小 弧长越大
    */
    double L, c, n, l;
    inline int sgn(double x)
    {
        //cout << x << endl;
        if (fabs(x - 0) < eps)
            return 0;
        else if (x > 0)
            return 1;
        else
            return -1;
    }
    int main()
    {
        while (scanf("%lf%lf%lf", &L, &c, &n), !(L<0&&c<0&&n<0))
        {
            l = (1 + n*c)*L;
            double beg = 0, end = L/2;
            while (sgn(end - beg) > 0)
            {
                double mid = (beg + end) / 2;
                double r = (4 * mid*mid + L*L) / 8 / mid;
                //cout << ":" << mid << endl;
                if (sgn(2*r*asin(L/2/r)-l) < 0)//弧长应当加大,所以h应该减小
                {
                    beg = mid;
                }
                else
                    end = mid;
            }
            printf("%.3lf
    ", beg);
        }
    }
  • 相关阅读:
    遗传算法中适值函数的标定与大变异算法
    遗传算法中几种不同选择算子及Python实现
    BZOJ_4025_二分图_线段树按时间分治+并查集
    BZOJ_1818_[Cqoi2010]内部白点 _扫描线+树状数组
    BZOJ_3165_[Heoi2013]Segment_线段树
    UOJ_21_【UR #1】缩进优化_数学
    UOJ_14_【UER #1】DZY Loves Graph_并查集
    BZOJ_5359_[Lydsy1805月赛]寻宝游戏_DP
    BZOJ_2813_奇妙的Fibonacci_线性筛
    51nod_1236_序列求和 V3 _组合数学
  • 原文地址:https://www.cnblogs.com/joeylee97/p/6958243.html
Copyright © 2011-2022 走看看