hdu1426 Sudoku Killer

Source: Internet
Author: User

Sudoku killertime limit:2000/1000ms (java/other) Memory limit:65536/32768k (Java/other) total submission (s): Ac cepted Submission (s): 28font:times New Roman | Verdana | Georgiafont Size:←→problem Description Since the first Sudoku World Championship from March 10, 2006 to 11th, Sudoku has become increasingly popular and valued.
It is said that at the 2008 Beijing Olympic Games, the Sudoku will be listed as a separate project to compete, the winner will be likely to receive a huge prize ——— HDU free 7th-day Tour plus LCY Autograph and a photo with HDU ACM team.
So the people of the world fought, for prizes day and night training Chafanbusi do not think. Of course also includes beginners Linle, but he is too stupid and not much patience, can only do the most basic Sudoku problem, but he still want to get those prizes, can you help him? You just have to tell him the answer so you don't have to teach him how to do it.

The rule of Sudoku is this: In a 9x9 box, you need to fill in the number 1-9 into a space, and make each row and column of the square contain 1-9 of these nine numbers. Also ensure that the space in the thick line divided into 9 3x3 squares also contains 1-9 of these nine numbers. For example, if you have such a problem, you can take a closer look at each line, each column, and each 3x3 square contains 1-9 of these nine numbers.

Examples:


Answer:
The input subject contains multiple sets of tests, separated by a blank line between each group. Each set of tests gives you a 9*9 matrix, separated by a space of two elements adjacent to the same line. Where 1-9 represents the already filled number of the position, the question mark (?) indicates the number you want to fill. Output for each set of tests, print its solution, separated by a space of two numbers adjacent to the same row. There is a blank line between the two sets of solutions.
For each set of test data it is guaranteed to have only one solution. Sample Input
7 1 2? 6? 3 5 8? 6 5 2? 7 1? 4?? 8 5 1 3 6 7 29 2 4? 5 6? 3 75? 6??? 2 4 11? 3 7 2? 9? 5?? 1 9 7 5 4 8 66? 7 8 3? 5 1 98 5 9? 4?? 2 3
Sample Output
7 1 2 4 6 9 3 5 83 6 5 2 8 7 1 9 44 9 8 5 1 3 6 7 29 2 4 1 5 6 8 3 75 7 6 3 9 8 2 4 11 8 3 7 2 4 9 6 52 3 8 66 4 7 8 3 2 5 1 98 5 9 6 4 1 7 2 3
AUTHORLINLESOURCEACM Summer Training Team Practice Competition (III)
#include <iostream>#include<cstdio>#include<cstring>using namespacestd;Charch[2];inta[Ten][Ten];inti,j,flag,l,p;structnode{intx, y;} s[ -];intCheck1 (intXintYintnum) {   for(intI=0;i<9; i++)    if(A[x][i]==num)return 0; return 1;}intCheck2 (intXintYintnum) {     for(intI=0;i<9; i++)      if(A[i][y]==num)return 0; return 1;}intCheck3 (intXintYintnum) {    intl,r,u,v; R= (x/3+1)*3-1; L=r-2;//l=x/3*3;v= (y/3+1)*3-1; U=v-2;  for(inti=l;i<=r;i++)         for(intj=u;j<=v;j++)         if(A[i][j]==num)return 0; return 1;}voidDfsintk) {  if(flag)return; if(k>l) {flag=1; return; }  intx=s[k].x; inty=s[k].y;  for(intI=1; i<=9; i++)  {      if(Check1 (x,y,i) && Check2 (x,y,i) &&Check3 (x,y,i)) {A[x][y]=i; DFS (k+1); if(flag)return; A[x][y]=0; }  }  return;}intMain () {p=0;  while(~SCANF ("%s",&ch)) {L=-1;  for(i=0;i<9; i++)             for(j=0;j<9; j + +)        {            if(i==0&& j==0)            {                if(ch[0]>'0'&& ch[0]<='9') a[i][j]=ch[0]-'0'; Else{A[i][j]=0; s[++l].x=i; S[l].y=J; }                 Continue; } scanf ("%s",&ch); if(ch[0]>'0'&& ch[0]<='9') a[i][j]=ch[0]-'0'; Else{A[i][j]=0; s[++l].x=i; S[l].y=J; }} Flag=0; DFS (0); if(p++) printf ("\ n");  for(i=0;i<9; i++)        {           for(j=0;j<8; j + +) printf ("%d", A[i][j]); printf ("%d\n", a[i][8]); }    }    return 0;}

hdu1426 Sudoku Killer

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.