who can help me? I want more test for this problem ,here is my code(+)
Послано
Badd 11 янв 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;
}