zoukankan      html  css  js  c++  java
  • POJ 1905(expanding rods)

    【题意描述】

    本题就是给定一个圆棒的热膨胀系数以及膨胀的温度,求最后变弯后中心点与原来中心点的距离。

    【思路分析】

    几何+二分:

    根据公式我们就可以利用二分进行查找了,当然二分是有技巧的,我们由于是double型数据,我们需要在设置循环条件时不能用high-low>0(会陷入系循环)而是需要设置精度esp(1e-5)写成high-low>esp就可以了。

    【AC代码】

    #include<iostream>
    #include<math.h>
    #include<iomanip>
    using namespace std;
    #define esp  1e-7
    int main()
    {
     double l,d,c;
     while(cin>>l>>d>>c)
     {
         if(l<0&&d<0&&c<0)
            break;
         if(l==0||c==0||d==0)
            cout<<"0.000"<<endl;
         else 
         {
            double high=l*0.5;
            double low=0.0;
            double s=(1+d*c)*l;
            double mid;
            while(high-low>esp)
            {
                 mid=(high+low)/2;
                double  r=(4*mid*mid+l*l)/(8*mid);
                double  s1=2*r*asin(l/(2*r));
                if(s1<s) low=mid;
                else high=mid;
            }
            double h=mid;
            cout<<fixed<<setprecision(3)<<h<<endl; 
         }
     }
     return 0;
    }

     

  • 相关阅读:
    SpringBoot学习历程
    日期和时间库Joda Time
    apache commons validator
    apache commons fileupload
    apache commons io
    apache commons compress
    apache commons codec
    apache commons email
    Http协议介绍
    Java原生Socket API
  • 原文地址:https://www.cnblogs.com/khbcsu/p/3891600.html
Copyright © 2011-2022 走看看