Lab8-Puzzle15
5530615821 นายเสฏฐวุฒิ สุดาฉิม (COM21900) (20/9/2555 (10:04:12))
MiniQuiz + TestScript |
JLab>javac FifteenPuzzle.java
JLab>
JLab>java Selftest
JLab> testPuzzle15 : ok ok ok ok ok ok ok ok ok ok (10.0/10.0)
JLab> : -----------------------------
JLab> : คุณได้ 10.0 คะแนน (เต็ม 10.0)
JLab> : -----------------------------
JLab> :<POINT>10.0</POINT> (<TOTAL>10.0</TOTAL> )
JLab>
ได้ 10 คะแนน |
Source Code |
public class FifteenPuzzle {
//---------------------------------------------------
public static boolean solvable15Puzzle(int[][] b) {
int B = 0;
int Bj = 0;
int L = 0;
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
if (b[i][j] == 0) {
B = (i + 1);
Bj = j;
}
}
}
int[] array = new int[15];
int count = 0;
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
if (b[i][j] != 0) {
array[count] = b[i][j];
count++;
}
}
}
for (int i = array.length - 1; i > 0; i--) {
for (int j = 0; j < i; j++) {
if (array[j] > array[i]) L++;
}
}
if ((L + B) % 2 == 0) {
return true;
} else return false;
}
//---------------------------------------------------
public static void main(String[] a) {
int[][] ok = { { 6, 5, 15, 11 },
{ 1, 3, 14, 12 },
{ 8, 9, 0, 2 },
{ 10, 4, 13, 7 } };
int[][] nok = { { 1, 2, 3, 4 },
{ 5, 6, 7, 8 },
{ 9, 10, 11, 12 },
{ 13, 15, 14, 0 } };
System.out.println(solvable15Puzzle(ok));
System.out.println(solvable15Puzzle(nok));
}
}
|
SM=4, CM=79, ST=86, KY=2090, TR=60:00
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 1092,1046,1058,1058,1046,1036,1046,;
ERR = 60:00 1058,1058,1046,1036,1046,;
ERR = 60:00 1152,;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 1058,1058,1046,1036,1046,;
ERR = 60:00 1058,1058,1046,1036,1046,60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
|
|