Sudoku is a long history, but also a particularly popular mathematical intelligence game, it not only has a strong interest, but also exercise our logical thinking ability, I in the "Strongest Brain" program also saw this project. Sudoku Game "Chessboard" is composed of 9,981 small squares, players require:
Players in each square, fill in 1 to 9 of any number, so that the entire chessboard of each column,
The algorithm originated from a friend for help. Friends in an electrical store to work, every year to the end of the need to do data, light on the ability of individuals can not be solved. So to mention this matter to me, as a proud program of apes, I said minutes to you to solve, but after detailed understanding, found that the problem is not so simple, so began to write an algorithm to help friends solve the problem.The problem is described as follows:Fill in all the blanks, guaranteeing that
A piece of code of the sudoku game forgot to use a search algorithm with the depth-first or breadth-first, and used some probability algorithms for improvement. In this case, I was afraid that I would accidentally delete it in a few years, g. JS seems to be included in another blog post, so I will not post it here.At the beginning, this code had some reasons. The ancients said: the mountains are not famous for being high, and the water is not famous f
I just saw that many people use DFS + Pruning for Sudoku .. What's wrong with my DLX...
But think about the fact that this search pruning is really a lot, but it's still faster than DLX...
# Include # Include String . H> # Include Using Namespace STD; # Define N 300000 # Define INF 0x3fffffff Char G [ 10 ] [ 10 ]; Int Ans [ 1000 ]; Int U [ 5000 ], D [ 5000 ], R [ 5000 ], L [ 5000 ], Num [ 5000 ], H [ 1000 ], Save [ 5000 ], Save1 [ 5000 ]
Question Portal
It is obviously a search. However, there is no pruning at the beginning, and the brute force search starts from,NaturallyT has 6 points.
#include
Consider pruning. From the perspective of human intelligenceAlthough I have never playedWe must start from a region with more options, because fewer decisions are available for us. So here we can also use this idea for reference. Every time we make statistics on the number of columns in each row, we have already filled in the number of
DFS ).
A very sad question is that the three arrays split into [9] [9] and thus cross-border wa.
Then there are empty rows between the two sets of outputs, but the empty rows cannot be output after the last group. PE many times.
#include
HDU 1426 Sudoku killer
This problem are relatively easy. The challenge is what to get a concise code. This post shares a very elegant one which traverses each cell of the board only once. The code is rewritten below.1 classSolution {2 Public:3 BOOLIsvalidsudoku (vectorChar>>Board) {4 BOOLrow[9][9] = {false}, col[9][9] = {false}, box[9][9] = {false};5 for(inti =0; I 9; i++) {6 for(intj =0; J 9; J + +) {7 if(Board[i][j]! ='.') {8 intnum = board[i][j]
Idea: Record the number of each column in each row that has appeared, the data is relatively weakIn addition POJ 3074 3076 must use pruning strategy, but to achieve more trouble, or after the DLX to do it againaccepted160k0ms#includePOJ 2676/2918 Sudoku (DFS)
HDU_4069
I remember the day before when I was discussing the Data independence issue in the group, I realized that I had another dancing links thing. As a result, the second day of the Fuzhou online competition had a Data independence issue ......
After learning the Dancing Links, I finally dropped this question A. the difference between this question and the ordinary Sudoku lies in the grouping problem. In the past, it was A small palace that could
Portal
This question is also a very violent search ......
Because the uniqueness is empty at the beginning, and there are only a lot of size restrictions, there is no need to worry about where to start the search, and then determine whether it is legal after the brute force search.
The most disgusting question is reading. Now I learned a trick to determine which part of the grid is located and use Lim [g] [I] [J] to indicate the relationship between the two grids I and j in the G Palace, the pro
/3) *3+k][int (J/3) *3+1]!=0:Try: List_a.remove (a[int (i/3) *3+k][int (J/3) *3+1]) except:Pass ifA[int (I/3) *3+k][int (J/3) *3+2]!=0:Try: List_a.remove (a[int (i/3) *3+k][int (J/3) *3+2]) except:Pass returnlist_areturnA[I][J]View CodeThe most important traversal lookup result function listDataGame_over=false #初始化未找到结果, locate the result settings game_over=truedefListData (a,posx,posy,f):GlobalGame_over#Game_over is a global variable rather than a
This article examples for everyone to share JS Lucky Draw nine Sudoku large turntable effect, for everyone's reference, the specific content as follows
Implementation code:
The above is the entire content of this article, I hope to learn JavaScript program to help you.
In this paper, we introduce the corresponding method of JavaScript to realize nine Sudoku, and share them for everyone's reference, the specific contents are as follows
Realize the idea:1, each lattice input value must be a number;
2, the input value can not be repeated;
3, the input value can not be less than 1 or greater than 9;
4, the value can not be empty;
5, add a total of 8, respectively, three horizontal, vertical three, two diagonal two
Sudoku concept, Idea, solution idea, C++code
The overall code of the blog's thinking is very clear, it is worth learning.The above blog code DFS knowledge output an array of answers, if the number is unique to multiple solutions, simply change the DFS code simple (as follows):
void dfs (int row,int col) {if (row>9)//if row exceeds 9 lines, direct output {for (int i=1; i
The Overall code is as follows:
#include
The above code looks pretty long,
PuzzlesThird-order magic Square (nine Sudoku). Try to fill in a 3x3 table with these 9 different integers, making the sum of the numbers on each row, each column, and each diagonal 1~9.PolicyExhaustive search. Lists all the integer fill schemes, and then filters them.JavaScript Solution
The code is as follows
Copy Code
/*** Created by Cshao on 12/28/14.*/ function Getpermutation (arr) {if (arr.length = = 1) {return [arr];}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.