# 编程之美1.15构造数独---置换法java版

脑筋急转弯一样的东西。。。
/*
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package Test;

/**
*
*/
public class SudokuDisplace {

public static void main(String[] args) {
int[][] shudu = new int[9][9];
int[][] arr = {{3, 5, 8}, {7, 9, 4}, {1, 6, 2}};
for (int i = 0; i < 9; i++) {
for (int j = 0; j < 9; j++) {
shudu[i][j] = 0;
}
}
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
shudu[i + 3][j + 3] = arr[i][j];
}
}
//置换行
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
if (i == 0) {
shudu[i + 3][j] =shudu[i+5][j+3];
shudu[i + 3][j + 6] = shudu[i+4][j+3];
}

if (i == 1) {
shudu[i + 3][j] = shudu[i+2][j+3];
shudu[i + 3][j + 6] = shudu[i+4][j+3];
}

if (i == 2) {
shudu[i + 3][j] = shudu[i+2][j+3];
shudu[i + 3][j + 6] = shudu[i+1][j+3];
}

}
}
//置换列
for(int i=0;i<3;i++){
for(int j =0;j<3;j++){
if(j ==0){
shudu[i][j + 3] = shudu[i+3][j+5];
shudu[i + 6][j + 3] = shudu[i+3][j+4];
shudu[i][j]=shudu[i+3][j+2];
shudu[i+6][j]=shudu[i+3][j+1];
shudu[i][j+6]=shudu[i+3][j+8];
shudu[i+6][j+6]=shudu[i+3][j+7];
}
if (j == 1) {
shudu[i][j + 3] = shudu[i+3][j+2];
shudu[i + 6][j + 3] = shudu[i+3][j+4];
shudu[i][j] = shudu[i+3][j-1];
shudu[i+6][j]=shudu[i+3][j+1];
shudu[i][j+6]=shudu[i+3][j+5];
shudu[i+6][j+6]=shudu[i+3][j+7];
}
if (j == 2) {
shudu[i][j + 3] = shudu[i+3][j+2];
shudu[i + 6][j + 3] = shudu[i+3][j+1];
shudu[i][j] = shudu[i+3][j-1];
shudu[i+6][j]=shudu[i+3][j-2];
shudu[i][j+6]=shudu[i+3][j+5];
shudu[i+6][j+6]=shudu[i+3][j+4];
}
}
}
for (int i = 0; i < 9; i++) {
for (int j = 0; j < 9; j++) {
if (j != 8) {
System.out.print(shudu[i][j] + "    ");
} else {
System.out.println(shudu[i][j]);
}

}
}
}

}


#### 编程之美1.15节：构造数独算法-回溯法和置换法

2012-04-16 10:34:20

#### 构造数独和解数独

2013-03-14 21:51:27

#### 关于《编程之美》中构造数独问题的小结

2017-07-20 14:43:43

#### 编程之美1.15——构造数独

2013-08-26 18:57:15

#### 编程之美 1.15 构造数独

2014-12-03 15:22:04

#### 编程之美1.15构造数独-----回溯法java版

2016-05-31 19:41:50

#### 读书笔记之编程之美 - 1.15 构造数独

2010-08-05 20:09:00

#### 编程之美：第一章 1.15构造数独

2014-09-14 21:08:49

#### 1.15 构造数独

2014-10-17 15:43:06

#### java编程之美(一)

2015-11-01 18:28:40