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);
        }
    }
  • 相关阅读:
    【前端进阶】VUE高性能组件引用
    「前端进阶」高性能渲染十万条数据(虚拟列表) (自己修改版本)
    页面缓存、离线存储技术localforage(案例篇)
    页面缓存、离线存储技术localforage(介绍篇)
    websocket快速搭建(node+websocket)
    一款程序员的杀手级应用:TabNine代码补全工具
    如何把es6的代码转成es5,ECMAScript 2015+代码转换神器——Babel
    如何使用echarts画一个简单k线图
    深入浅出理解 . 深拷贝 . 浅拷贝
    JS高级一看就懂什么是原型链
  • 原文地址:https://www.cnblogs.com/joeylee97/p/6958243.html
Copyright © 2011-2022 走看看