Here you will find solutions of many problems on spoj. If you want solution of some problem which is not listed in blog or have doubt regarding any spoj problem (which i have solved) or any programming concept (data structure) you can mail me @ raj.nishant360@gmail.com

And my humble request to you all that don't copy the code only try to understand the logic and algorithm behind the code. I have started this because if you tried as hard as you can and still can't find any solution to the problem then you can refer to this.
You can read my answer how to start competitive programming CLICK HERE

Thursday, February 20, 2014

RROOT - REAL ROOTS

SOLUTION TO RROOT SPOJ - REAL ROOT SPOJ

RROOT - REAL ROOTS : (link to the question)

x^2 + 2*b*x + c = 0 , for the real roots of this quadratic equation, delta should be >= 0, which is 4*(b^2 - c) here ,
 or  b*b - c >= 0  which mean if c <= 0 , no need to bother about b since delta will always be positive.
but when c > 0, then we need to check where delta is non - negative.
follow the steps:
b^2 - c  < 0   ( this part we gotta exclude ). 
b^2 < c 
here by, we can conclude that all we have to do is to exclude the area  inclosed by parabola with the upper side of square.

After all the evaluation, we'll get 1 - 1/(3 * sqrt(n/2)) as an answer.
#include<stdio.h>
#include<math.h>

int main()
{
    int t;  double d;

    scanf("%i",&t);

    while(t--)
    {
        scanf("%lf",&d);

        printf("%0.6lf\n", 1 - 1/(3*sqrt(d/2)));

    }
    return 0;
}

No comments:

Post a Comment

Your comment is valuable to us