][j]); the printf ("******\n"); - }*/ $ while(!qu.empty ()) the { theQunode tmp =Qu.front (); the //printf ("%d\n", tmp.num); the Qu.pop (); -Mians = min (mians,yd-p[tmp.num].y); in the if(Tmp.num = = n+1) the { AboutOK =1; the returnTmp.step; the } the for(inti =0; i ) + { - if(!Vis[mp[tmp.num][i]]) the {Bayi //printf ("%d to%d\n", Tmp.num,mp[tmp.num][i]); theVis[mp[tmp.num][i]] =1; t
You don't need to describe the question. This was mentioned in the album http://www.matrix67.com/blog/archives/122 written by matrix67. (This question is also mentioned when I talk about searching today =)
I wrote it in this way. It is actually DFS, with the same idea. The transfer is very intuitive. SHR (>) SHL (
Fast. In addition, it is easy to solve the problem by changing to Queen n.
// 8 queens // 92 // time = 0.0010 s # include
Place eight queens on an 8*8 chessboard, so that they are not on a horizontal or vertical or diagonal line. You can imagine that the first piece occupies the first position () on the first board, and then places the second piece on the second Board to meet the conditions of the Queen, for example, (2, 3. When there is no position available, you must move the position of the pawns in the previous line, that is, to trace back. For other details, refer t
How do I use Python to crawl the beauty picture and save it locally?1. What data is available?Homecoming NameSchool Campus SchoolThe URL of the beauty queen picture Img_ulr2. How do I get it?Open the Web page http://www.xiaohuar.com/hua/, open the development tool, study each picture corresponding HTML, find the lawBulk crawl through Python's scrapy frameworkEnvironmental statement:Python 3.50Scrapy LibraryWhat are the problems?1. How do I remove a du
problem DescriptionN-Queens are placed in the N*n's checkered checkerboard, making them not attack each other (that is, any 2 queens are not allowed to be in the same row, in the same column, or in a diagonal line with a 45-angle checkerboard border.)Your task is to find out how many legal placement methods are available for a given n.InputThere are several lines, one positive integer n≤10 per line, indicating the number of boards and queens, or, if n=0, the end. Outputa number of rows, one posi
1, in the mobile phone download installation of the latest version of the daily P map, that will see 3.7 girls day today I want to be the Queen's subtitle, click into;
2, in the subtitle below, click as shown in the button can be replaced by a variety of subtitles, click the bottom of the middle of the shooting button can be successful yo.
3, so that the successful production of the Queen's subtitles, the effect of the following figure shown
All right, this is the
The eight Queens question, that is, eight queens on the 8*8 lattice, requires each queen to be different rows, different columns, and no longer diagonal.
Solution One: full permutation solution. Eight queens do not walk, then assume that there is an array size of 8, the array subscript represents the row, 0~7 will be filled, the array of each subscript position of the value of the current queen's column, that is, the subscript value for the Queen's ro
Problem Description: Eight Queens can not attack each other, that is, eight queens can not walk, the same column, different on the same diagonal line,Diagonal can also be divided into left diagonal and right diagonalLeft diagonal satisfies: i-j+7 are equal (I,j are one and two dimensional coordinates respectively)Right diagonal satisfies: i+j are equalThe code is as follows:#include using namespacestd;inte_q[8][8];intr[ the];intle[ the];intq[8];intCount =0;voidEn_queens (int);intMain () { for(in
Idea: Use a one-dimensional array hang [num] = I, num to represent the row num, I to represent the column I, and calculate n = 1 ~ Different Placement quantities of Queen 10, and then table
# Include
Link to the question: Ultraviolet A 11538-Chess Queen
In an n? On m's board, put two queens, asking the two queens to attack each other and how many ways to put them.
Solution: because the Queen's attack range is vertical lines, horizontal lines, and diagonal lines, we can enumerate the positions of the two queens on each line. For example, there are eight diagonal lines, then there will be C (82) species for the two queens.Number of rows n, m posit
Php backtracking algorithm solves the n Queen problem. The basic method of backtracking is to search, or a well-organized search method that can avoid unnecessary search. This method is suitable for solving problems with a large number of combinations. The basic method of backtracking is to search, or a well-organized search method that can avoid unnecessary search. This method is suitable for solving problems with a large number of combinations.
In
put King Zhou King together with his dynasty destroyed, you can't do it! Then who is evil and who is self-employed, and does not need you to chatter about other people's is not.Women to do housework, but housework not as the whole of life, the most important thing is to do a good job, rely on the ability to eat, self-reliance will let oneself own half the sky, give yourself a reasonable reason to eat.To be a woman is to be reservedTo be a woman to be reserved, the reservation must be kept, can
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.