不要问我辛普森怎么来的,其实我也不知道。。。
#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:\n" , ++ ca ) ;
printf ( "%.2lf\n" , h - x ) ;
if ( T ) puts ( "" ) ;
}
return 0 ;
}