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 1066. Garland

Binary search, WA on test #7. Why?
Posted by Maigo Akisame 20 Jun 2004 19:56
program ural1066;
var
  n,i:integer;
  a,b,c,l,r,h2:real;
  h1:real;
begin
  readln(n,h1);
  l:=0;r:=maxlongint;
  repeat
    b:=h1;
    h2:=(l+r)/2;c:=h2;
    for i:=3 to n do begin
      a:=b;b:=c;c:=2*(b+1)-a;
      if c<0 then break;
    end;
    if c<0 then l:=h2 else r:=h2;
  until r-l<1e-4;
  writeln(abs(c):0:2);
end.
Re: Binary search, WA on test #7. Why?
Posted by Saturn 22 Jun 2004 02:03
You should use math to solve this problem
Re: Binary search, WA on test #7. Why?
Posted by Maigo Akisame 22 Jun 2004 20:35
When I inputed 1000 1, my prog gave me 996004.06. So I knew it was the prob of accuration. But when I changed '1e-4' in the last line but two into '1e-10', it worked well on my PC, but WA test #1 on the judge!
  It's even stranger!
Re: Binary search, WA on test #7. Why?
Posted by Saturn 23 Jun 2004 02:25
You solutions is not correct.You can try these test:
100 100 =>7921.00
10 11 =>32.00
123 456 =>10128.86
111 111 =>9891.00
8 15 =>9.75
5 10 =>0.67
70 50 =>3835.14
1000 1=>996004.00
(It was given by an ACed program)
If you don't know how to solve this problem by maths I can tell you.
I used only 9 var and 12 lines program, O(N).
Goodluck!:)
I've fixed my error. AC now. Thanks.
Posted by Maigo Akisame 23 Jun 2004 04:18
Subj