Date post: | 26-May-2015 |
Category: |
Technology |
Upload: | hafizhatim |
View: | 873 times |
Download: | 2 times |
KELOMPO
K 2
PE
MO
DE
LA
N N
- QU
EE
N P
AD
A P
RO
GR
AM
JA
VAPBO
PENGENALAN
DESIGNPEMODELANDAN SIMULASI OUTPUTNYAPENERAPAN ALGORIMA KE
N-QUEEN
DESIGN1
2 34
5
678
PEMODELANPAPAN CATUR
QUEEN
SETQUEEN
REMOVEQUEEN
KOREKSI
SIMULASI OUTPUTNYA
public class Queens{ public static boolean isConsistent(int[] q, int n) { for (int i = 0; i < n; i++) { if (q[i] == q[n]) return false; // same column if ((q[i] - q[n]) == (n - i)) return false; // same major diagonal if ((q[n] - q[i]) == (n - i)) return false; // same minor diagonal } return true; }
public static void printQueens(int[] q) { int N = q.length; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { if (q[i] == j) System.out.print("Q "); else System.out.print("* "); } System.out.println(); } System.out.println(); }
public static void enumerate(int N) { int[] a = new int[N]; enumerate(a, 0); } public static void main(String args[]) { Scanner S=new Scanner(System.in); System.out.print("Enter no. of Queens: "); int N = S.nextInt(); enumerate(N); }}