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

#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;
}
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.
aaakkk could you tell me why b=B/2 ? [1] // Problem 1200. Horns and Hoofs 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.
Macarie programatorul in actiune Re: could you tell me why b=B/2 ? // Problem 1200. Horns and Hoofs 5 Aug 2004 00:20
the maximum of a 2 degree function is at point -b/2a, in our case b/2...
Gheorghe Stefan caterinca // Problem 1200. Horns and Hoofs 5 Aug 2004 02:16
brute force works fine... :D