Posted: Fri Apr 06, 2007 1:15 pm
First search your problem. If you find any thread then use it. If no thread is found then and only then you are allowed to open a new thread.
However, check the thread.
However, check the thread.
Code: Select all
#define err 1e-10
Code: Select all
#define err 1e-13
Code: Select all
#include<iostream>
#include<cmath>
#define e ( 1e-15 )
using namespace std;
double L,n,C,S,S2,theta,r;
inline double ABS( double x )
{
return( x>0 ? x : -x );
}
inline double f( double x )
{
return( S2 * sin( x/2 ) - L * x );
}
double Bisection( double L,double R )
{
double M;
double fL = f(L) ,fR = f(R), fM;
if( ABS( fR )<e )return R;
if( ABS( fL )<e )return L;
while( R-L>e )
{
M = ( L+R ) / 2;
fM = f(M);
if( ABS( fM )<e )
return M;
else if( fL*fM<0 )
R = M, fR = fM;
else
L = M, fL = fM;
}
return L;
}
int main()
{
cout.setf( ios::fixed );
cout.precision( 3 );
const double PI = acos( -1.000 );
while( cin>>L>>n>>C,( L>=0 || n>=0 || C>=0 ) )
{
if( C==0 || n==0 )
{
cout<<"0.000"<<endl;
continue;
}
S = ( 1.000 + n*C ) * L;
S2 = 2.000*S;
theta = Bisection( e,PI-e );
r = S/theta;
cout<<( r - r*cos( theta/2.000 ) )<<endl;
}
}
Code: Select all
1000 100 0.0001
15000 10 0.00006
15000 20 0.00006
15000 20 0.00089
10 1 0.001
10 0 0.001
1 5 0.2333
5 1 0.2333
5300 100 0.5323
15 415 0.0044
15 15 3.333
-1 -1 -1
Code: Select all
61.329
225.020
318.255
1228.775
0.194
0.000
0.000
1.529
0.000
0.000
0.000
Code: Select all
1000 100 0.0001
0 100 0.0001
1000 0 0.0001
1000 100 0
15000 10 0.00006
10 0 0.001
-112 -1121212 -1324
Code: Select all
61.329
0.000
0.000
0.000
225.020
0.000