ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1066. Garland

Binary Search AC program
Posted by Bogdan A. Stoica [fireatmyself] 1 Sep 2005 17:20
#include <stdio.h>
#define eps 0.00000001

double A, B=((1<<31)-1), DMin=((1<<31)-1);
int N;

void bs()
{
        double p1 = A, p2 = 0, mij, a1, a2, a3, min;
        int i;

        while ((p1-p2)>eps)
        {
                min = A;
                mij  = (p1+p2)/2;
                a1 = A; a2 = mij;
                for (i = 2; i < N; i++)
                {
                        a3 = 2*(a2+1)-a1;
                        a1 = a2;
                        a2 = a3;
                        if (a3 < 0)
                        {
                                p2 = mij+eps;
                                break;
                        }
                        else
                            if (min > a3) min = a3;
                }
                if (i == N)
                {
                   if ((B-a3)<eps) p2=2*p1;
                   if ((DMin-min) > eps) DMin = min, B = a3;
                   p1 = mij-eps;
                }
        }
}

int main()
{
        scanf("%d %lf", &N, &A);
        bs();
        printf("%.2lf\n", B);

        return 0;

}
Re: Binary Search AC program
Posted by jagatsastry 18 Nov 2007 21:33
Can you just explain in simple terms the method you've used.

Edited by author 01.12.2007 02:29