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 1200. Horns and Hoofs

who can help me? I want more test for this problem ,here is my code(+)
Posted by Badd 11 Jan 2003 09:32
My algorithm is about Binary Search.


#include <stdio.h>
int main()
{
    float a,b,m=0;
    long n,l,l2,lf,rg,c,k;
    float m1=0,m2=0;
    FILE* fname=stdin;
    FILE* fout=stdout;
    fscanf(fname,"%f%f%ld",&a,&b,&n);
    for (l=0; l<=n; l++)
    {
        if (l>0)
            if ( (l*l)-(l-1)*(l-1) >=
a ) break;
        lf=1; rg=n-l; c=(lf+rg)/2; k=0;
        for (; lf<=rg; c=(lf+rg)/2)
        {
            if ( (c*c)-(c-1)*(c-1) <
b )
            { k=c; lf=c+1; }
            else rg=c-1;
        }
        if ( (l*a)+(k*b) - (l*l+k*k) > m )
        {
            m=(l*a)+(k*b) -
(l*l+k*k);
            m1=l; m2=k;
        }
    }
    m=(m1*a)+(m2*b) - (m1*m1+m2*m2);
    if (m==0) m=0;
    fprintf(fout,"%.2f\n%.0f %.0f\n",m,m1,m2);
    fclose(fname); fclose(fout);
    return 0;
}