10668 - Expanding Rods
Moderator: Board moderators
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.
Ami ekhono shopno dekhi...
HomePage
HomePage
-
- Learning poster
- Posts: 60
- Joined: Sun Apr 16, 2006 7:59 pm
Replace
with
Hope you get accepted.
Code: Select all
#define err 1e-10
Code: Select all
#define err 1e-13
Ami ekhono shopno dekhi...
HomePage
HomePage
You have to be patient. If you find no reply (for a long time) then you can post in that thread again, like "Can anyone help?". Actually when we log in, we check the new posts. Thats why we can check your problem again.
Ami ekhono shopno dekhi...
HomePage
HomePage
-
- Learning poster
- Posts: 60
- Joined: Sun Apr 16, 2006 7:59 pm
-
- Learning poster
- Posts: 60
- Joined: Sun Apr 16, 2006 7:59 pm
I've used 1e-15 as my epislon, but the online judge system keeps give me constant WA. Can somebody check my code? I choose Bisection as my algo.
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;
}
}
Re: 10668 - Expanding Rods
i used long double , and EPS as 1e-13
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
Re: 10668 - Expanding Rods
I used binary search on theta, after getting a couple of wrong answers, when I handled cases like n = 0, l = 0 or c = 0, I got Accepted. Here are some cases:
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
You tried your best and you failed miserably. The lesson is 'never try'. -Homer Simpson