| Show all threads     Hide all threads     Show all messages     Hide all messages | 
| 37 Test | Novopashin | 2010. Sasha the Young Grandmaster | 2 Nov 2019 21:53 | 3 | 
| 37 Test Novopashin 14 Apr 2015 01:38 check your Knight with n = 3Really nice tip, tvm bro. | 
| i got AC,perhaps be useful for you | 1508090114 | 2010. Sasha the Young Grandmaster | 23 Jan 2017 11:39 | 1 | 
| first of all trytest
 1
 1 1
 all answer will be 0
 
 here is my code
 
 [code deleted]
 
 Edited by moderator 20.10.2019 21:28
 | 
| #wa 20 What's wrong ? | spidey | 2010. Sasha the Young Grandmaster | 27 Nov 2016 17:30 | 2 | 
| This is my code
 import java.util.*;
 
 public class Task_2010 {
 static void kingStep(int n, int x, int y){
 long countKing = 0;
 if((x - 1) > 0) countKing++;
 if((x - 1) > 0 && y + 1 <= n) countKing++;
 if((y + 1) <= n) countKing++;
 if((x + 1) <= n && (y + 1) <= n) countKing++;
 if((x + 1) <= n) countKing++;
 if((x + 1) <= n && (y - 1) > 0) countKing++;
 if((y - 1) > 0) countKing++;
 if((x - 1) > 0 && (y - 1) > 0) countKing++;
 System.out.println("King: " + countKing);
 }
 static void knightStep(int n, int x, int y){
 long countKnight = 0;
 if((x - 2) > 0 && (y + 1) <= n) countKnight++;
 if((x - 2) > 0 && (y - 1) > 0) countKnight++;
 if((y + 2) <= n && (x - 1) > 0) countKnight++;
 if((y + 2) <= n && (x + 1) <= n) countKnight++;
 if((x + 2) <= n && (x + 1) <= n) countKnight++;
 if((x + 2) <= n && (y - 1) > 0) countKnight++;
 if((y - 2) > 0 && (x + 1) <= n) countKnight++;
 if((y - 2) > 0 && (x - 1) > 0) countKnight++;
 System.out.println("Knight: " + countKnight);
 }
 static long bishopStep(int n, int x, int y) {
 long countBishop = 0;
 int left = x - 1;
 int right = n - x;
 if(y + left <= n){
 countBishop += left;
 } else countBishop += n - y;
 if(y + right <= n){
 countBishop += right;
 } else countBishop += n - y;
 if(y - left > 0){
 countBishop += left;
 } else countBishop += y - 1;
 if(y - right > 0){
 countBishop += right;
 } else countBishop += y - 1;
 System.out.println("Bishop: " + countBishop);
 return countBishop;
 }
 static long rookStep(int n, int x, int y){
 long countRook = (x - 1) + (n - x) + (y - 1) + (n - y);
 System.out.println("Rook: " + countRook);
 return countRook;
 
 }
 public static void main(String[] args){
 Scanner sc = new Scanner(System.in);
 int n = sc.nextInt();
 int x = sc.nextInt();
 int y = sc.nextInt();
 
 kingStep(n,x,y);
 knightStep(n,x,y);
 long queen = (bishopStep(n,x,y) + rookStep(n,x,y));
 System.out.println("Queen: " +  queen);
 
 }
 }
 | 
| An interesting way of coding it | Egor | 2010. Sasha the Young Grandmaster | 18 Nov 2016 02:11 | 1 | 
| There is an interesting way to code it.
 For each piece we can have a function like this:
 pair<string, int> get_king(int n, int x0, int y0)
 {
 int cnt = 0;
 for (int dx = -1; dx <= 1; dx++)
 for (int dy = -1; dy <= 1; dy++)
 if (dx != 0 || dy != 0)
 {
 int x = x0 + dx;
 int y = y0 + dy;
 cnt += (x >= 1 && x <= n && y >= 1 && y <= n);
 }
 
 return { "King", cnt };
 }
 
 In the main code we just do the following loop:
 for (auto get : { get_king, get_knight, get_bishop, get_rook, get_queen })
 {
 auto res = get(n, x, y);
 cout << res.first << ": " << res.second << endl;
 }
 
 After that the function for queen look very easy:
 pair<string, int> get_queen(int n, int x0, int y0)
 {
 int cnt = get_rook(n, x0, y0).second + get_bishop(n, x0, y0).second;
 return { "Queen", cnt };
 }
 
 If you have any ideas on how to code it better, please write them here :)
 | 
| If you need good tests see it: | IlushaMax | 2010. Sasha the Young Grandmaster | 10 Jul 2016 14:09 | 1 | 
| At first check all tests with n<=4. If all of them cheked already then try to check all cells for n=8 (1/1; 1/2; 1/3; 1/4; 2/2; 2/3....)and for n=9. Don't be afraid you'll find your mistake on first tests))
 Edited by author 10.07.2016 14:33
 | 
| Give me some tests please | Ivan Metelev UFU SESC | 2010. Sasha the Young Grandmaster | 2 Jun 2016 17:15 | 5 | 
| I have WA#16, give me some tests please
 Edited by author 09.11.2014 18:38
 Edited by author 09.11.2014 18:35
 
 Edited by author 09.11.2014 18:35
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
I 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.
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!
 | 
| Test #20 | spidey | 2010. Sasha the Young Grandmaster | 19 Feb 2016 17:59 | 1 | 
| Can anyone give me 20 test? I have WA and i don't know why | 
| Test #15 | picture | 2010. Sasha the Young Grandmaster | 19 Dec 2015 16:24 | 1 | 
|  | 
| WA8 Help | [kubsu] Eugene Kudinov | 2010. Sasha the Young Grandmaster | 26 Nov 2015 21:34 | 1 | 
| WA8 Help [kubsu] Eugene Kudinov 26 Nov 2015 21:34 // delgot AC
 
 Edited by author 26.11.2015 22:07
 | 
| WA 10 some ideas>? | Roman Samokhin | 2010. Sasha the Young Grandmaster | 9 Jan 2015 06:02 | 1 | 
|  | 
| Test #8. Can you give me more test? | Frank | 2010. Sasha the Young Grandmaster | 26 Aug 2014 06:00 | 2 | 
| 64 4
 
 ans
 King: 8
 Knight: 8
 Bishop: 9
 Rook: 10
 Queen: 19
 
 1987
 1947 1952
 ans
 King: 8
 Knight: 8
 Bishop: 2056
 Rook: 3972
 Queen: 6028
 
 17
 17 17
 
 ans
 King: 3
 Knight: 2
 Bishop: 16
 Rook: 32
 Queen: 48
 
 
 
 | 
| TL #33 | 6eJIa9IzZzTeHb | 2010. Sasha the Young Grandmaster | 9 Jul 2014 05:15 | 1 | 
| TL #33 6eJIa9IzZzTeHb 9 Jul 2014 05:15 IF YOU HAVE TL #33
 TRY TEST:
 1
 1 1
 
 FUNNY BUG=)
 | 
| Some tests | NickC8 | 2010. Sasha the Young Grandmaster | 17 Nov 2013 01:38 | 4 | 
| I'm getting WA#4, can you give some tests?Re: Some tests Vedernikoff 'Goryinyich' Sergey (HSE: АОП) 16 Nov 2013 03:31 1 1 1King: 0
 Knight: 0
 Bishop: 0
 Rook: 0
 Queen: 0
 
 2 2 2
 King: 3
 Knight: 0
 Bishop: 1
 Rook: 2
 Queen: 3
 
 100000000 99999999 100000000
 King: 5
 Knight: 3
 Bishop: 99999999
 Rook: 199999998
 Queen: 299999997
 
 98765432 10987654 32109876
 King: 8
 Knight: 8
 Bishop: 120740737
 Rook: 197530862
 Queen: 318271599
Thank you, remembered about cases when n<4 until your post. Got AC! Have you used predefined output for these (n<4) cases?
 Edited by author 16.11.2013 03:51
Re: Some tests Vedernikoff 'Goryinyich' Sergey (HSE: АОП) 17 Nov 2013 01:38 No, well designed algo equally works for all possible cases |