Nyoj 722 Sudoku

Source: Internet
Author: User

This has been done before, but it is, after finding a solution, I quit.

Can be easily changed to find out the form of all the solutions.


Sudoku

Time limit: ms | Memory limit:65535 KB

Difficulty:4

  • Describe

  • Sudoku is a logic game that uses paper and pens to make calculations. The player needs to infer the number of all remaining spaces according to the known numbers on the 9x9 disk, and the numbers in each row, each column, and every 3*3 Palace are 1-9 and do not repeat. Every qualified Sudoku puzzle has and only one answer, and the reasoning method is based on it, and any problem without solution or multi-solution is unqualified.

    One day HRDV met a claim is the world's most difficult Sudoku problem, as a qualified programmer, can casually to the difficulty bow, so he decided to make a program to solve it.

    650) this.width=650; "src=" Http://acm.nyist.net/JudgeOnline/admin/kind/attached/20130604182400_52995.jpg "border= "0" style= "border:0px none;"/>

    • Input

    • The first line has a number n (0< n <100), indicating that there are n sets of test data, each set of test data is composed of a 9*9 nine Gongge, 0 means that the corresponding lattice is empty

    • Output

    • Output a 9*9 of nine Gongge, for the answer of this Sudoku

    • Sample input

    • 10 0 5 3 0 0 0 0 08 0 0 0 0 0 0 2 00 7 0 0 1 0 5 0 04 0 0 0 0 5 3 0 00 1 0 0 7 0 0 0 60 0 3 2 0 0 0 8 00 6 0 90 0 4 0 0 0 0 3 00 0 0 0 0 9 7 0 0
    • Sample output

    • 1 4 5 3 2 7 6 9 8 8 3 9 6 5 4 1  2 7 6 7 2 9 1 8 5 4 3 4 9 6 1  8 5 3 7 2 2 1 8 4 7 3 9 5 6 7  5 3 2 9 6 4 8 1 3 6 7 5 4 2 8  1 9 9 8 4 7 6 1 2 3 5 5 2 1 8  3 9 7 6 4 
#include  <iostream> #include  <cstring>using namespace std;int sudoku[9][9] ;//Determine if the number in the blank position meets the requirements on the row or column bool judge1 (int x, int y, int n) {int i;for (i=0;i <9;i++) {//Judgment   column if ((sudoku[i][y]==n)  &&  (i!=x)) return false;//judgment   line if (Sudoku [x] [I]==n)  &&  (i!=y)) Return false;} Return true;} Determine whether the number filled in the blank position meets the requirements within nine Gongge Bool judge2 (int x, int y, int n) {int xx,yy,i,j;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;elsereturn false;return true;} Fills a blank array bool fill (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)) return true;sudoku[x][y]=0;}} Elsereturn fill (m+1); return false;} Int main () {int n,i, J,k;cin>>n;while (n--) {memset (sudoku,0,sizeof (Sudoku)); for (i=0;i<9;i++) for (j=0;j<9;j++) cin>> Sudoku[i][j];if (Fill (0)) {for (i=0;i<9;i++) {for (j=0;j<9;j++) cout << sudoku[i][j] < <  " "; Cout << endl;}} return 0;}


Nyoj 722 Sudoku

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.