modify code

pull/6/head
左程云 4 years ago
parent 9a797f4ef7
commit 396affee4e

@ -38,10 +38,12 @@ public class Code06_IslandProblem {
List<Dot> dotList = new ArrayList<>(); List<Dot> dotList = new ArrayList<>();
for (int i = 0; i < row; i++) { for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++) { for (int j = 0; j < col; j++) {
if (board[i][j] == 1) {
dots[i][j] = new Dot(); dots[i][j] = new Dot();
dotList.add(dots[i][j]); dotList.add(dots[i][j]);
} }
} }
}
UnionSet<Dot> us = new UnionSet<>(dotList); UnionSet<Dot> us = new UnionSet<>(dotList);
for (int j = 1; j < col; j++) { for (int j = 1; j < col; j++) {
if (board[0][j - 1] == 1 && board[0][j] == 1) { if (board[0][j - 1] == 1 && board[0][j] == 1) {
@ -196,42 +198,43 @@ public class Code06_IslandProblem {
int[][] board2 = copy(board1); int[][] board2 = copy(board1);
int[][] board3 = copy(board1); int[][] board3 = copy(board1);
System.out.println("感染方法、并查集(map实现)、并查集(数组实现)的运行结果和运行时间");
System.out.println("数据规模 : " + row + " * " + col);
long start = 0; long start = 0;
long end = 0; long end = 0;
start = System.currentTimeMillis(); start = System.currentTimeMillis();
System.out.println(solve1(board1)); System.out.println("感染方法的运行结果: " + solve1(board1));
end = System.currentTimeMillis(); end = System.currentTimeMillis();
System.out.println((end - start) + " ms"); System.out.println("感染方法的运行时间: " + (end - start) + " ms");
System.out.println("===================");
start = System.currentTimeMillis(); start = System.currentTimeMillis();
System.out.println(solve2(board2)); System.out.println("并查集(map实现)的运行结果: " + solve2(board2));
end = System.currentTimeMillis(); end = System.currentTimeMillis();
System.out.println((end - start) + " ms"); System.out.println("并查集(map实现)的运行时间:" + (end - start) + " ms");
System.out.println("===================");
start = System.currentTimeMillis(); start = System.currentTimeMillis();
System.out.println(solve3(board3)); System.out.println("并查集(数组实现)的运行结果: " + solve3(board3));
end = System.currentTimeMillis(); end = System.currentTimeMillis();
System.out.println((end - start) + " ms"); System.out.println("并查集(数组实现)的运行时间:" + (end - start) + " ms");
System.out.println("===================");
System.out.println("==============================================");
row = 10000; row = 10000;
col = 10000; col = 10000;
System.out.println("感染方法、并查集(数组实现)的运行结果和运行时间");
System.out.println("数据规模 : " + row + " * " + col);
board1 = generateRandomMatrix(row, col); board1 = generateRandomMatrix(row, col);
board3 = copy(board1); board3 = copy(board1);
start = System.currentTimeMillis(); start = System.currentTimeMillis();
System.out.println(solve1(board1)); System.out.println("感染方法的运行结果: " + solve1(board1));
end = System.currentTimeMillis(); end = System.currentTimeMillis();
System.out.println((end - start) + " ms"); System.out.println("感染方法的运行时间:" + (end - start) + " ms");
System.out.println("===================");
start = System.currentTimeMillis(); start = System.currentTimeMillis();
System.out.println(solve3(board3)); System.out.println("并查集(数组实现)的运行结果: " + solve3(board3));
end = System.currentTimeMillis(); end = System.currentTimeMillis();
System.out.println((end - start) + " ms"); System.out.println("并查集(数组实现)的运行时间:" + (end - start) + " ms");
System.out.println("===================");
} }

Loading…
Cancel
Save