zoukankan      html  css  js  c++  java
  • uva 1356 Bridge ( 辛普森积分 )

    uva 1356 Bridge ( 辛普森积分 )

    不要问我辛普森怎么来的,其实我也不知道。。。

    #include<stdio.h>
    #include<math.h>
    #include<string.h>
    #include<algorithm>
    using namespace std ;
    
    double d , h , m , b , l , w ;
    
    double f ( double x ) {
        double a = 4.0 * m / w / w ;
        return sqrt ( 1.0 + 4 * a * a * x * x ) ;
    }
    
    double simp ( double a , double b ) {
        double c = a + ( b - a ) / 2 ;
        return ( f( a ) + 4 * f ( c ) + f ( b ) ) * ( b - a ) / 6 ;
    }
    
    double asr ( double a , double b , double eps , double A ) {
        double c = ( a + ( b - a ) / 2 ) ;
        double L = simp ( a , c ) , R = simp ( c , b ) ;
        if ( fabs ( L + R - A ) <= 15 * eps )
            return L + R + ( L + R - A ) / 15.0 ;
        return asr ( a , c , eps / 2 , L ) + asr ( c , b , eps / 2 , R ) ;
    }
    
    double asr ( double a , double b , double eps ) {
        return asr ( a , b , eps , simp ( a , b ) ) ;
    }
    
    int main () {
        int T , ca = 0 ;
        scanf ( "%d" , &T ) ;
        while ( T -- ) {
            scanf ( "%lf%lf%lf%lf" , &d , &h , &b , &l ) ;
            double n = ceil ( b / d ) ;
            l = l / n , w = b / n ;
            double x = 0 , y = h ;
            while ( fabs ( y - x ) >= 1e-8 ) {
                m = ( x + y ) / 2 ;
                double k = 2 * asr ( 0 , w / 2 , 1e-8 , simp ( 0 , w / 2 ) ) ;
                if ( k < l ) x = m ;
                else y = m ;
            }
            printf ( "Case %d:
    " , ++ ca ) ;
            printf ( "%.2lf
    " , h - x ) ;
            if ( T ) puts ( "" ) ;
        }
        return 0 ;
    }
    


  • 相关阅读:
    初学者常用的LINUX命令
    logging模块全总结
    logging模块初识
    xpath知多少
    selenium常用的API
    系统测试基础(适合入门)
    JavaScript正则表达式(一)
    webpack2学习(二)
    webpack2学习(一)
    SQL语句学习
  • 原文地址:https://www.cnblogs.com/keanuyaoo/p/3367591.html
Copyright © 2011-2022 走看看