Sudoku Solver_sudoku solver 16by16_The Lonely Square Root 13 Blog

class=”htmledit_views”> 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. 1. My answer: Backtrack Traverse each position, and use 1~9 to place this position, and check if the character does not match. It takes a lot of time, no reason, it may need to be optimized // // main.cpp // sudo // // Created by zjl on 16/4/30. // Copyright 2016 zjl. All rights reserved. // #include #include using namespace std; bool judge(vector<vector> board, int r, int c, char target){ for(int i = 0; i < 9; i++){ if(board[r][i]==target || board[i][c]==target) return false; } int br = 3*(r/3), cr = 3*(c/3); for(int k = br; k < br+3; k++){ for(int j = cr; j < cr+3; j++){ if(board[k][j] == target) return false; } } return true; } void print_vec(vector<vector> b){ for(int p = 0; p < b. size(); p++){ for(int q = 0; q < b[p].size(); q++){ cout<<b[p][q]<<" "; } cout<<endl; } } bool Sudo(vector<vector>& board, int row, int col){ bool b = false; if(board[row][col]!=’.’){ if(col+1…

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索