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

Help me, please!!! I don't know what is wrong with this!!!
Posted by Flyer 3 Apr 2002 14:32
#include <iostream.h>
#include <stdio.h>

float A,B;
int K;

float S (long a, long b)
{
 return a*A+b*B-a*a-b*b;
}

float Maxsb (long a, long& b)
{
 b=B/2;
 if (b<0) b=0;
 if (b+a>K)
  b=K-a;
 return S (a,b);
}

int main ()
{
 cin >> A >> B >> K;
 float max=0,maxsb;
 int ma=0,mb=0;
 long a,b;
 for (a=0;a<=K;a++)
 {
  maxsb=Maxsb (a,b);
  if (maxsb>max)
  {
   max=maxsb;
   ma=a;
   mb=b;
  }
 }
 printf ("%.2f\n",max);
 printf ("%d %d\n",ma,mb);
 return 0;
}
Re: Help me, please!!! I don't know what is wrong with this!!!
Posted by Komandos 8 Apr 2002 12:20
I think that operator b=B/2 is incorrect. b must be closest integer for B/2.
For example, if A=2, B=1.8 and K=100 then rigth answer is ma=1 and mb=1.
could you tell me why b=B/2 ?
Posted by aaakkk 19 Nov 2002 09:26
> I think that operator b=B/2 is incorrect. b must be closest integer
for B/2.
> For example, if A=2, B=1.8 and K=100 then rigth answer is ma=1 and
mb=1.
Re: could you tell me why b=B/2 ?
Posted by Macarie programatorul in actiune 5 Aug 2004 00:20
the maximum of a 2 degree function is at point -b/2a, in our case b/2...
caterinca
Posted by Gheorghe Stefan 5 Aug 2004 02:16
brute force works fine... :D