|  | 
|  | 
| back to board | Give me some tests please I have WA#16, give me some tests please
 Edited by author 09.11.2014 18:38
No subject  Edited by author 09.11.2014 18:35
 
 Edited by author 09.11.2014 18:35
Re: No subject I can poste my bad code, can someone help me?
 var
 a, b, n, x, y: int64;
 
 begin
 readln(n, x, y);
 write('King: ');
 if n = 1 then writeln(0) else
 if ((x = 1) and (y = 1)) or ((x = n) and (y = 1)) or ((x = 1) and (y = n)) or ((x = n) and (y = n)) then writeln(3) else
 if (x = 1) or (y = 1) or (x = n) or (y = n) then writeln(5) else writeln(8);
 write('Knight: ');
 if (n = 1) or (n = 2) or ((n = 3) and (x = 2) and (y = 2)) then writeln(0) else
 if (((y = 1) and (x = 1)) or ((y = n) and (x = n)) or ((y = 1) and (x = n)) or ((y = n) and (x = 1))) or (n = 3) and ((x = 2) or (y = 2)) then writeln(2) else
 if ((x = 2) and ((y = 1) or (y = n))) or ((x = n - 1) and ((y = 1) or (y = n)) or ((y = 2) and ((x = 1) or (x = n))) or ((Y = N - 1) and ((x = 1) or (x = n))))  then writeln(3) else
 if (((x >= 3) and (x <= n - 2)) and ((y = 1) or (y = n))) or (((y >= 3) and (y <= n - 2)) and ((x = 1) or (x = n))) or ((x = 2) and ((y = 2) or (y = n - 1)) or ((x = n - 1) and ((y = 2) or (y = n - 1)))) then  writeln(4)  else
 if (((x >= 3) and (x <= n - 2)) and ((y = 2) or (y = n - 1))) or (((y >= 3) and (y <= n - 2)) and ((x = 1) or (x = n)))  then writeln(6) else writeln(8);
 
 if n = 1 then a := 0 else
 if (n - x >= x) and (n - x >= n - y) and (n - x >= y) then a := (n - 1) + 2 * (x - 1) else
 if (x >= n - x) and (x >= n - y)   and (x >= y)   then a := (n - 1) + 2 * (n - x) else
 if (y >= x)   and (y >= n - y)   and (y >= n - x) then a := (n - 1) + 2 * (n - y) else
 if (n - y >= x) and (n - y >= n - x) and (n - y >= y) then a := (n - 1) + 2 * (y - 1);
 if n = 1 then b := 0 else b := (n - 1) * 2;
 writeln('Bishop: ', a);
 writeln('Rook: ', b);
 writeln('Queen: ', a + b);
 end.
 
 Edited by author 01.06.2016 11:32
Re: No subject Posted by d_m  2 Jun 2016 14:44I don't know where is problem in your code. But you can insert in the beginning something like that:
 if x > (n + 1) div 2 then x := n + 1 - x;
 if y > (n + 1) div 2 then y := n + 1 - y;
 
 and remove all comparisons with n. It will make your code much simpler.
Re: No subject A much more simple approach would be creating something likefunction InBounds(x0, y0, xshift, yshift: longint): boolean;
 begin
 inc(x0, xshift); inc(y0, yshift);
 InBounds:=((x0 >= 1) and (x0 <= N) and (y0 >= 1) and (y0 <= N));
 end;
 This will allow to check king and knight in a much more simple and elegant way.
 King:
 res:=-1;
 for i:=-1 to 1 do
 for j:=-1 to 1 do
 if InBounds(x0, y0, i, j) then inc(res);
 writeln('King: ', res);
 Knight:
 res:=0;
 for i:=1 to 2 do //length before turn
 for j:=0 to 1 do //sign 1
 for k:=0 to 1 do begin //sign 2
 if InBounds(x0, y0, (j + j - 1) * i, (k + k - 1) * (3 - i)) then inc(res);
 end;
 writeln('Knight: ', res);
 
 For rook, it's always N + N - 2, even for N = 1, so there was no need to specifically bring up that case...
 Queen is rook + bishop, and bishop i'd say is the "hardest" part here, but well, you just take the minimum of squares he can move to in each 4 directions, just be attentive...
 Good luck!
 | 
 | 
|