Retrospective method coefficient single problem

Source: Internet
Author: User

in the near time, the backtracking algorithm is much more, and the understanding of the algorithm is also in-depth. Today, I stumbled across a picture, a sudoku puzzle that was not done in high school. The "candidate remainder method" was used, and it was not done because of too much trouble. But it was saved, and it was suddenly seen today. At that time just finished the C language, the Hanoi recursion is not too understanding, so it has been dragged to the present.
650) this.width=650; "alt=" Picture "src=" http://r.photo.store.qq.com/psb?/V109X33K1cyrDg/ q72tmuro6fml5amtkt5podrsyafdn4oazc89examgh0!/o/daiaaaaaaaaa&bo=vqoaasad0aifaoy! "style=" vertical-align:top; width:853px;height:640px; "/>

with Do, the code is as follows

#include <iostream>usingnamespace std; intsudoku[9][9]={0}; //to determine the number of blanks in a blank position in the row, Whether the column meets the requirements BoolJudge1 (int x, int y, int n) {             int i;                        for (i=0;i<9;i++)              {                         //Judgment   Column                           if (sudoku[i][y]==n &&  (i!=x))                                       returnfalse;                         //Judgment   Line                           if (sudoku[x][i]==n &&  (i!=y))                                       returnfalse;             }              return true;}  //determine whether the number filled in the white space within nine Gongge meets the requirements BoolJudge2 (int x, int y, int n) {             int xx,yy,i,j;      & Nbsp;     xx=x/3;             yy=y/3;            for (i=xx*3;i<xx*3+3;i+ +)                          for (j=yy*3;j<yy*3+3;j++)                                       if (sudoku[i][j]==n)                                                    if (i==x&& j==y)                                                                continue;                                                   else                                                                Returnfalse;    &nBsp;       return true;}  //padding Empty array boolfill (int m) {            int  n,x,y;            x=m/9;             y=m%9;             if  (m>=81)                          return true;             if  (sudoku[x][y]==0)              {                         for (n=1;n<=9;n++)                          {                                      sudoku[x][y]=n;                                      if (Judge1 (x,y,n) &&judge2 (x,y,n))                                                   if (Fill (m+1))                                                                returntrue;                                      sudoku[x][y]=0;                                                                           }            }             else                         return fill (m+1);              return false;}  intmain () {            //input initial sudoku              int i,j,k;             cout <<  "Input initial sudoku data, blank with 0 instead of"  <<endl;             for (i=0;i<9;i++)                           for (j=0;j<9;j++)                                      cin>>sudoku[i][j];                         /*for (i=0;i<9;i++)              {                         for (j=0;j<9;j++)                                       cout<< sudoku[i][j]  <<  " ";                         cout << endl;             }*/                         if (Fill (0))//Fill Sudoku blank position complete              {                         for (i=0;i<9;i++)                          {                                      for (j=0;j<9;j++)                                       {                                                  cout< < sudoku[i][j] <<  " ";                                                   if (! ( (j+1)%3)                                                                cout<<  "| ";                                      }                                      cout<< endl;                                      if (! ( (i+1)%3)                                       {                                                  for (k=0;k<12;k++)                                                                cout<< "_ _ ";                                                  cout<< endl;                                      }                         }              }             else                         cout <<  " This Sudoku has no solution, please note the game rules or check the original Sudoku is wrong " << endl;              return 0;}


After running the

650) this.width=650; "alt=" Picture "src=" http://r.photo.store.qq.com/psb?/v109x33k1cyrdg/yk6jhtyhjon* pwq2xpci8cn4j23jrxmlmi8zyiszm10!/o/dacaaaaaaaaa&bo=zwoaakwe0gifapu! "style=" vertical-align:top;width:870px; height:571px; "/>


This article is from the "hacker" blog, make sure to keep this source http://anglecode.blog.51cto.com/5628271/1618797

Retrospective method coefficient single problem

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.