Sudoku Solver填数
来源:互联网 发布:pp助手mac版工具箱 编辑:程序博客网 时间:2024/06/02 15:04
Write a program to solve a Sudoku puzzle by filling the empty cells.
Empty cells are indicated by the character '.'
.
You may assume that there will be only one unique solution.
A sudoku puzzle...
...and its solution numbers marked in red.
- bool isValid(vector<vector<char> > &board, int a, int b) {
- int i,j;
- for(i = 0; i < 9; i++)
- if(i != a && board[i][b] == board[a][b])
- return false;
- for(j = 0; j < 9; j++)
- if(j != b && board[a][j] == board[a][b])
- return false;
- int x = a/3*3;
- int y = b/3*3;
- for(i = 0; i < 3; i++)
- for(j = 0; j< 3; j++)
- if(x+i != a && y+j != b && board[x+i][y+j] == board[a][b])
- return false;
- return true;
- }
- bool solveSudokudfs(vector<vector<char> > &board)
- {
- for(int i = 0; i < 9; i++)
- for(int j = 0; j < 9; j++)
- {
- if(board[i][j] == '.')
- {
- for(int k = 1; k <= 9; k++)
- {
- board[i][j] = '0' + k;
- if(isValid(board,i,j) && solveSudokudfs(board))
- return true;
- board[i][j] = '.';
- }
- return false;
- }
- }
- return true;
- }
- void solveSudoku(vector<vector<char> > &board) {
- // Note: The Solution object is instantiated only once.
- solveSudokudfs(board);
- }
0 0
- Sudoku Solver填数
- 数独求解 Sudoku Solver
- Leetcode-Sudoku Solver(数独)
- Sudoku Solver:数独求解
- LeetCode: Sudoku Solver (数独求解)
- LeetCode Sudoku Solver 数独C++程序
- [LeetCode] [数独问题] Sudoku Solver
- Sudoku Solver 数独的解决方案
- Sudoku Solver 求解数独问题
- 【LeetCode】37. Sudoku Solver 数独求解
- 36/37. Sudoku Solver 数独问题
- LeetCode:Valid Sudoku,Sudoku Solver(数独游戏)
- leetcode_Valid Sudoku and Sudoku Solver (数独游戏) _easy
- leetcode 37. Sudoku Solver 36. Valid Sudoku 数独问题
- Sudoku Solver
- Sudoku Solver
- Sudoku Solver
- Sudoku Solver
- Javascript函数既可以实例化成对象也可以是可用的函数
- 生成照片宽高设置4:3
- 闭包的应用场景
- 常用排序算法
- POJ 1017 Packets(水~)
- Sudoku Solver填数
- 冒泡排序 回顾
- DB2中字符、数字和日期类型之间的转换
- javaScript里的setTimeout()函数
- Maven仓库—Nexus环境搭建及简单介绍
- Spring AOP 动态代理
- Java语言 快速排序
- 51nod1354选数字
- Activity的四大启动模式