zoukankan      html  css  js  c++  java
  • poj1905——二分法求单调函数零点解方程

    poj1905——二分法求单调函数零点解方程

    Expanding Rods
    Time Limit: 1000MS   Memory Limit: 30000K
    Total Submissions: 12773   Accepted: 3291

    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
    题意:长度为L的铁片如图所示,升高温度C后会有一定程度的形变,长度变为NewL,呈圆弧状,求铁片中点偏离的高度
    思路:数学题,解方程时构造函数二次求导求变化趋势,二分确定零点范围,怀念高考前刷数学试卷做导数题的时光。此题需注意精度以及数据为0的特判。
    /**
     * Start at 12:53
     * End at 13:08
     * Problem: poj1905
     * Author: __560
     */
     #include<iostream>
     #include<cstdio>
     #include<cstring>
     #include<cstdlib>
     #include<algorithm>
     #include<math.h>
    
     using namespace std;
    
     const int maxn=1000100;
     const int INF=(1<<28);
     const double Pi=3.1415927;
     const double Exp=0.000000000001;
    
     double L,T,C;
     double NewL;
    
     double f(double x)
     {
         return L*x-NewL*sin(x);
     }
    
     double BinSearch(double left,double right)
     {
         while(fabs(left-right)>Exp){
            double mid=(left+right)/2;
            if(f(mid)<0) left=mid;
            else if(mid>0) right=mid;
         }
         return left;
     }
    
     int main()
     {
         while(scanf("%lf%lf%lf",&L,&T,&C)!=EOF){
            if(L==-1&&T==-1&&C==-1) return 0;
            if(L==0||T==0||C==0) puts("0.000");
            else{
                NewL=(1+C*T)*L;
                double x=BinSearch(Exp,Pi);
                double R=NewL/(2*x);
                double d=sqrt(R*R-L*L/4);
                printf("%.3f
    ",R-d);
            }
         }
     }
    View Code


    没有AC不了的题,只有不努力的ACMER!
  • 相关阅读:
    小白们应该知道,在Eclipse当中怎样在编译页面当中显示行号.
    严重:Parse error in application web.xml file at jndi:/localhost/day_29/WEB-INF/web.xml解决办法
    linux 系统下,忘记密码的快捷解决方法。
    eclipse 当中,修改文本编辑框的字体大小
    如何在linux当中,大量的添加用户
    04文件操作1
    03python面向对象编程之多态和枚举6
    03python面向对象编程5
    03python面向对象编程4
    03python面向对象编程2
  • 原文地址:https://www.cnblogs.com/--560/p/4380596.html
Copyright © 2011-2022 走看看