zoukankan      html  css  js  c++  java
  • POJ1905-Expanding Rods-二分答案

    一根细棒升温时会变长,在两面墙中间,会变成一个弓形。

    给出变长后的长度,求新的细棒中心与没伸长时的中心的距离。

    简单的数学推导后就可以二分答案了,一开始没完全掌握二分的姿势,wa了好多。而且poj double输出要用%f,用%lf就wa了。

    #include <cstdio>
    #include <cmath>
    #include <algorithm>
    
    using namespace std;
    
    const double eps = 1e-5;
    double n,c,L;
    
    double func(double x)
    {
        //if(fabs(x-0) < eps) return ;
        double r = (x*x+L*L/4.0)/(2*x);
        return 2*r*asin(L/(2.0*r));
    }
    
    int main()
    {
        while(scanf("%lf%lf%lf",&L,&n,&c))
        {
            if(L<0 && n<0 && c<0)
                break;
    
            double low = 0.0,high = 0.5*L;
            double mid = (low+high)/2.0;
            double s = (1+n*c)*L;
            double ans = 0;
    
            while(high-low>eps)
            {
                //printf("%lf %lf %lf
    ",low,mid,high);
                //printf("%lf %lf %lf
    ",func(low),func(mid),func(high));
    
                if(func(mid) < s)
                    low = mid;
                else
                    high = mid;
    
                mid = (low+high)/2.0;
            }
            //printf("%f %f
    ",mid,L);
            printf("%.3f
    ",mid);
        }
    }
  • 相关阅读:
    mysql高并发配置
    php xml转array的方法
    双系统,一系统损坏后的解决方案之硬盘启动
    最长公共前缀
    罗马数字转整数
    回文数
    整数反转
    一、数组---两数之和
    从尾到头打印链表
    替换空格
  • 原文地址:https://www.cnblogs.com/helica/p/5173796.html
Copyright © 2011-2022 走看看