编程之美1.15构造数独---置换法java版
来源:互联网 发布:学java可以开发游戏吗 编辑:程序博客网 时间:2024/05/30 23:01
脑筋急转弯一样的东西。。。
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */package Test;/** * * @author Administrator */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]); } } } }}
0 0
- 编程之美1.15构造数独---置换法java版
- 编程之美1.15节:构造数独算法-回溯法和置换法
- 编程之美1.15构造数独-----回溯法java版
- 编程之美 1.15 构造数独
- 读书笔记之编程之美 - 1.15 构造数独
- 编程之美...构造数独
- 编程之美1.15——构造数独
- 编程之美1.15——构造数独
- 编程之美:第一章 1.15构造数独
- 编程之美——构造数独
- 编程之美中构造数独例子
- [编程之美] PSet1.15 构造数独
- 编程之美-构造数独方法整理
- POJ 2676 数独 && 编程之美1.15
- 编程之美...求解数独
- 关于《编程之美》中构造数独问题的小结
- 《编程之美》读书笔记(七):数独游戏解析
- 1.15 构造数独
- 【C++ 学习】01 资源整理
- bootStrap实习原理
- XListView的布局
- POJ 2151 Check the difficulty of problems 概率DP
- HDU-1095
- 编程之美1.15构造数独---置换法java版
- change background color in chrome
- 数组元素过半问题
- java之用户登录界面
- 九度OJ 1078
- shell中$(( ))与$( )还有${ }的区别
- Solr 6.0 学习(七) solr创建索引原理
- LeetCode 326. Power of Three
- android.os.Build代码翻译