haha

package IM; import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class TheRook { static int T, n, Ans, t; static int[][] map; // static void findCompetitor(int x, int y){ // boolean flag = false; // for(int i = y+1; i < n; i++){ // if(map[x][y] == 1){ // if(map[x][i] == 2){ // map[x][y] = 0; // map[x][i] = 0; // break; // }else if(map[x][i] == 3){ // flag = true; // break; // } // }else if(map[x][y] == 2){ // if(map[x][i] == 1){ // map[x][y] = 0; // map[x][i] = 0; // break; // }else if(map[x][i] == 3){ // flag = true; // break; // } // }else // break; // } // for(int i = x+1; i < n; i++){ // if(flag == true){ // break; // } // if(map[x][y] == 1){ // if(map[i][y] == 2){ // map[x][y] = 0; // map[i][y] = 0; // break; // }else if(map[i][y] == 3){ // break; // } // }else if(map[x][y] == 2){ // if(map[i][y] == 1){ // map[x][y] = 0; // map[i][y] = 0; // break; // }else if(map[i][y] == 3){ // break; // } // }else // break; // } // } static void findCompetitor1(int x, int y) { for (int i = y + 1; i < n; i++) { if (map[x][i] == 2) { map[x][y] = 0; map[x][i] = 0; break; } else if (map[x][i] == 3) break; } } static void findCometitor2(int x, int y) { for (int i = y + 1; i < n; i++) { if (map[x][i] == 1) { map[x][y] = 0; map[x][i] = 0; break; } else if (map[x][i] == 3) break; } } static void findCompetitor11(int x, int y) { boolean flag = false; for (int i = y + 1; i < n; i++) { if (map[x][i] == 3) flag = true; break; } for (int i = x + 1; i < n; i++) { if (flag == true) { break; } if (map[i][y] == 2) { map[x][y] = 0; map[i][y] = 0; break; } if (map[i][y] == 3) { break; } } } static void findCompetitor22(int x, int y) { boolean flag = false; for (int i = y + 1; i < n; i++) { if (map[x][i] == 3) flag = true; break; } for (int i = x + 1; i < n; i++) { if (flag == true) { break; } if (map[i][y] == 1) { map[x][y] = 0; map[i][y] = 0; break; } else if (map[i][y] == 3) { break; } } } public static void main(String[] args) throws FileNotFoundException { Scanner sc = new Scanner(new File("input_therook.txt")); T = sc.nextInt(); for (int tc = 1; tc <= 1; tc++) { Ans = 0; t = sc.nextInt(); n = sc.nextInt(); map = new int[n][n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { map[i][j] = sc.nextInt(); } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (map[i][j] == 1) { findCompetitor1(i, j); } else if (map[i][j] == 2) { findCometitor2(i, j); } } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (map[i][j] == 1) { findCompetitor11(i, j); } else if (map[i][j] == 2) { findCompetitor22(i, j); } } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (map[i][j] == 1 || map[i][j] == 2) { Ans++; } } } // System.out.println("#" + tc + " " + Ans); } } }
There are black rooks and white rooks randomly in the 100 by 100 arena. The rook can move on both horizontal and vertical without being blocked by the same color one. The rooks have a higher priority from left to right and from top to bottom. The Rocks with greater priority move firstly. Firstly, the rook find competitor in the row, then in the column. If the rook found the competitor, it would move to attack the competitor.
Collision of a black rook and white rook causes the destruction of both rooks without any trace, damage to other rooks.
The rooks will stop when no competitor within the area that they can move.
If any rook meet a rock, they can’t continue moving.
If all rooks are destroyed or stopped, the game is over. Please, write a function which returns the number of remaining rooks in the area after the match.

[Example]
If you look down the arena in the sky, you can see the picture below:
Rock is shown as red cell.
As a result, the return number should be 6 because there are 3 while rooks and 3 black rooks left.

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.