10668 - Expanding Rods

All about problems in Volume 106. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post by Jan »

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.
Ami ekhono shopno dekhi...
HomePage
ayeshapakhi
Learning poster
Posts: 60
Joined: Sun Apr 16, 2006 7:59 pm

Post by ayeshapakhi »

Thanks a lot for help.
i've seen that thread before posting here. There's no testcases.
I can't find any logical error in my code (used bisection and it seems all of my i/o 's are ok) and finally i posted my code in another thread but there's no reply...
so......

thanks.
Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post by Jan »

Replace

Code: Select all

#define err 1e-10
with

Code: Select all

#define err 1e-13
Hope you get accepted.
Ami ekhono shopno dekhi...
HomePage
Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post by Jan »

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
ayeshapakhi
Learning poster
Posts: 60
Joined: Sun Apr 16, 2006 7:59 pm

Post by ayeshapakhi »

Strange!!
Really it got acc!.........
Infinite thanks for u.

Thanks again.
ayeshapakhi
Learning poster
Posts: 60
Joined: Sun Apr 16, 2006 7:59 pm

Post by ayeshapakhi »

Sorry for inconvenience....
Thanks a lot for help.......
gba356
New poster
Posts: 15
Joined: Sat Apr 28, 2007 10:12 am
Location: Taiwan

Post by gba356 »

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;
    }
}

tryit1
Experienced poster
Posts: 119
Joined: Sun Aug 24, 2008 9:09 pm

Re: 10668 - Expanding Rods

Post by tryit1 »

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
plamplam
Experienced poster
Posts: 150
Joined: Fri May 06, 2011 11:37 am

Re: 10668 - Expanding Rods

Post by plamplam »

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
Post Reply

Return to “Volume 106 (10600-10699)”