Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Zombie virus
//'main' method must be in a class 'Rextester'. //Compiler version 1.8.0_111 import java.util.*; import java.lang.*; class Rextester { public static int[] xPoint = { 1, 0, 0, -1 }; public static int[] yPoint = { 0, 1, -1, 0 }; static int count, count2; public static void main(String args[]) { Readfile(); } public static void CCTVToEnd(int xBegin, int yBegin, int xEnd, int yEnd, int[][] matrix, int zombieTouchEnd, int size, int step) { if (step == zombieTouchEnd && xBegin == xEnd && yBegin == yEnd) { count2++; } else { for (int i = 0; i < 4; i++) { int tempX = xBegin + xPoint[i]; int tempY = yBegin + yPoint[i]; if (step < zombieTouchEnd) { if (0 <= tempX && tempX < size && 0 <= tempY && tempY < size && (matrix[tempX][tempY] == 0 || matrix[tempX][tempY]==2)) { int a=matrix[tempX][tempY]; matrix[tempX][tempY] = 5; CCTVToEnd(tempX, tempY, xEnd, yEnd, matrix, zombieTouchEnd, size, step + 1); if(tempX==xEnd&&tempY==yEnd) { matrix[tempX][tempY] = 2; }else { matrix[tempX][tempY] = 0; } } } } } } public static void BeginToCCTV(int xBegin, int yBegin, int xCCTV, int xEnd, int yEnd, int yCCTV, int[][] matrix, int zombieTouchCCTV, int zombieTouchEnd, int size, int step) { if (step == zombieTouchCCTV && xBegin == xCCTV && yBegin == yCCTV) { count++; CCTVToEnd(xCCTV, yCCTV, xEnd, yEnd, matrix, zombieTouchEnd, size, step); } else { for (int i = 0; i < 4; i++) { int tempX = xBegin + xPoint[i]; int tempY = yBegin + yPoint[i]; if (step < zombieTouchCCTV) { if (0 <= tempX && tempX < size && 0 <= tempY && tempY < size && (matrix[tempX][tempY] == 0 || matrix[tempX][tempY] == 3)) { matrix[tempX][tempY] = 4; BeginToCCTV(tempX, tempY, xCCTV, xEnd, yEnd, yCCTV, matrix, zombieTouchCCTV, zombieTouchEnd, size, step + 1); if(tempX==xCCTV&&tempY==yCCTV) { matrix[tempX][tempY] = 3; }else { matrix[tempX][tempY] = 0; } } } } } } public static void Readfile() { BufferedReader reader; try { reader = new BufferedReader(new FileReader("D:\\Long\\Homework\\Zombie virus\\input.txt")); String line = reader.readLine(); int case_seat = Integer.parseInt(line); line = reader.readLine(); while (line != null) { String[] size_matrix = line.split("\\s+"); if (size_matrix.length == 2) { int size = Integer.parseInt(size_matrix[0]); int zombieTouchEnd = Integer.parseInt(size_matrix[1]); int[][] matrix = new int[size][size]; line = reader.readLine(); String[] zombie = line.split("\\s+"); int xBegin = Integer.parseInt(zombie[0]); int yBegin = Integer.parseInt(zombie[1]); int xEnd = Integer.parseInt(zombie[2]); int yEnd = Integer.parseInt(zombie[3]); // System.out.println(xBegin + " " + yBegin + " " + xEnd + " " + yEnd); line = reader.readLine(); String[] CCTV = line.split("\\s+"); int xCCTV = Integer.parseInt(CCTV[0]); int yCCTV = Integer.parseInt(CCTV[1]); int zombieTouchCCTV = Integer.parseInt(CCTV[2]); line = reader.readLine(); for (int row = 0; row < size; row++) { for (int col = 0; col < size; col++) { matrix[xBegin - 1][yBegin - 1] = 1; matrix[xEnd - 1][yEnd - 1] = 2; matrix[xCCTV - 1][yCCTV - 1] = 3; } } count = 0; count2 = 0; BeginToCCTV(xBegin-1, yBegin-1, xCCTV-1, xEnd-1, yEnd-1, yCCTV-1, matrix, zombieTouchCCTV, zombieTouchEnd, size, 0); System.out.println(count2); } } } catch (IOException e) { e.printStackTrace(); } } }
run
|
edit
|
history
|
help
0
Document management system - build unordered list (table of contents) recursively
1
Interference
Add Index of max number in an array
Kochergina_4
ArrayOperation
move zeros to end of array
Length of longest substring
Трикотаж
Duplicate in string