Lab8-Puzzle15


5530493521  นายวรกูล สัจจะบริบูรณ์ (COM22023) (9/7/2012 (12:28:54 PM))

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 roo = 0;
for (int y = 0; y < 4; y++) {
  for (int x = 0; x < 4; x++) {
    if(b[y][x]==0) roo = y+1;
    }
  }

int[] a = new int[16];
int count = 0;
for (int y = 0; y < 4; y++) {
  for (int x = 0; x < 4; x++) {
      a[x+ y*4] = b[y][x];
    }
  }
for (int i = 0; i < 16; i++) {
  for (int j = i + 1; j < 16; j++) {
    if(a[i]>a[j] && a[j]!=0)count++;
    }
  }
if((count+roo)%2==1)return false;





    return true;
  }
  //---------------------------------------------------
  public static void main(String[] a) {
    int[][] ok = { { 1, 2, 3, 4 },
                    { 5, 6, 7, 8 },
                    { 9, 10, 12, 15 },
                    { 13, 14, 11, 0 } };
    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=0, CM=31, ST=34, KY=1402, 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 ;
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 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;