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! Why wrong answer?
Posted by aaa 22 Mar 2002 15:35
I've got trouble in 1200.
Help me please.
Here is my programme:
{$n+}
const zero=1e-5;
var k,c,d,e,f:longint; a,b,max,g:extended;
begin
  assign(input,''); reset(input);
  assign(output,''); rewrite(output);
  read(a,b); read(k);
  max:=-1e10;
  for c:=0 to k do begin
    d:=round(b/2);
    if d<0 then d:=0;
    if c+d>k then d:=k-c;
    g:=-sqr(d)+b*d+a*c-sqr(c);
    if g>max-zero then begin
      max:=g; e:=c; f:=d;
    end;
  end;
  writeln(max:0:2); writeln(e,' ',f);
  close(input); close(output);
end.
Thank you very much!
Sorry,I post a wrong programme. Here is the currunt one. Help me!
Posted by aaa 22 Mar 2002 15:45
{$n+}
const zero=1e-20;
var k,c,d,e,f:longint; a,b,max,g:extended;
begin
  assign(input,''); reset(input);
  assign(output,''); rewrite(output);
  read(a,b); read(k);
  max:=-1e10;
  for c:=0 to k do begin
    d:=round(b/2);
    if d<0 then d:=0;
    if c+d>k then d:=k-c;
    g:=-sqr(d)+b*d+a*c-sqr(c);
    if g>max-zero then begin
      max:=g; e:=c; f:=d;
    end;
  end;
  writeln(max:0:2); writeln(e,' ',f);
  close(input); close(output);
end.
Re: Sorry,I post a wrong programme. Here is the currunt one. Help me!
Posted by raxtinhac 22 Mar 2002 17:43
 Use trunc, not round.
 Don't use const zero, only need " if g > max ".
 I'm sure you'll get AC
Thank you for your help!
Posted by aaa 23 Mar 2002 05:45
Could you tell me why use trunc(b/2) instead of other value? I think there maybe some maths reason.
Posted by aaakkk 19 Nov 2002 08:35
>  Use trunc, not round.
>  Don't use const zero, only need " if g > max ".
>  I'm sure you'll get AC