|
|
вернуться в форумWA#6, please help me!! here my code Послано Bobur 4 фев 2009 00:10 program Project1; {$APPTYPE CONSOLE} uses SysUtils; var n, m, d, dn, dm, dns, dms, n1, m1, answer, x : integer; function teng(delta : integer) : integer; var ans : integer; begin ans := delta * 2; if odd(delta) and (odd(dn) or odd(dm)) then begin if odd(n1) then begin if odd(n) then dec(ans) else inc(ans) end else if odd(n) then inc(ans) else dec(ans); end; teng := ans; end; begin read(m, n); if n < m then begin x := n; n := m; m := x; end; n1 := TRUNC(sqrt(n)); if sqr(n1)=n then dec(n1); m1 := TRUNC(sqrt(m)); if sqr(m1)=m then dec(m1); d := n1-m1; dn := n - sqr(n1); dm := m - sqr(m1); dns := sqr(n1+1)-n; dms := sqr(m1+1)-m; if d = dn - dm then answer := teng(d) else begin if dm >= dn then begin writeLn(2*d+dm-dn); exit end; if dms >= dns then begin writeLn(2*d+dms-dns); exit end; if d > dn-dm then answer := (dn-dm)*2 + teng(d-dn+dm) else answer := (dns-dms)*2 + teng(d-dns+dms); end; writeLn(answer); end. Re: WA#6, please help me!! here my code Послано OpenGL 4 фев 2009 01:07 Try to find other algoritm. On small test your program gives a right answers. But on this test: 119 751 answer is not true. Good luck! :) |
|
|