Question of the lover. Java code

xiaoxiao2021-03-06  13

/ * * 8 lover issues: * * Question Description: * Place 8 lover in a 8 × 8 chessboard, requires no conflict between each lover two or two * (in each horizontal column, column, oblique only A lover). * * Data Representation: * Use a 8-bit 8-based number to represent the lover of the chessboard: * For example: 45615353 said: * Episode 0 Lonese in the fourth position * Lein 1 Lone in the 5th position * 2 columns in the 6th position *. . . * Chapter 7 Lonity in the third position * * cyclic variables from 00000000 to 7777777 (8-based number), traversing all the cases of lover * Programs in the program with an octal number of one-dimensional array DATA [] * * Detection conflict: * Cross collision: data [i] == data [j] * oblique conflict: (DATA [i] i) == (Data [J] J) or (Data [i] -i ) == (DATA [J] -J) * * Benewhere: * Adopt loop, not the regulations, system resources account for less * can calculate N-lover issues * Popularize the problem, you can block the problem, in distributed There are multiple computers in the environment. * * Todo: * Enumeration section can also be optimized, and more judgment conditions can be faster. * Output section can modify the output of the board * * @Author Cinc 2002-09-11 * * /

Public class queen {int size; int result (int size) {this.size = size; resultcount = 0; int data [] = new int [size]; int count; // all possible somewhere INT i, j; // calculate the number of possible cases count = 1; for (i = 0; i

/ * * Test this situation Valentine's arrangement * * / public boolean test (int [] data) {INT I, J; for (i = 0; i

// main () is here. Public static void main (string args []) {(new queen ()). Compute (8);}}

转载请注明原文地址:https://www.9cbs.com/read-48998.html

New Post(0)