HDU 5547 Violence

Source: Internet
Author: User

Sudoku

Time limit:3000/1000 MS (java/others) Memory limit:65535/65535 K (java/others)
Total submission (s): 1064 Accepted Submission (s): 362


Problem Descriptionyi Sima is one of the best counselors of Cao Cao. He likes to play a funny game himself. It looks like the modern Sudoku, but smaller.

Actually, Yi Sima was playing it different. First of all, he tried to generate a4x4 Board with every row contains 1 to 4, every column contains 1 to 4. Also He made sure that if we cut the the board to four2x2 pieces, every piece contains 1 to 4.

Then, he removed several numbers from the board and gave it to another guy to recover it. As other counselors is not as smart as Yi Sima, Yi Sima always made sure that the board is only have one to recover.

Actually, you is seeing this because you ' ve passed through to the Three-kingdom age. You can recover the board-make Yi Sima happy and be promoted. Go and do it!!!

Inputthe first line of the input gives the number of test cases,T(1≤t≤) .T test Cases follow. Each test case is starts with a empty line followed by 4 lines. Each line consist of 4 characters. Each character represents the number in the corresponding cell (one of ' 1 ', ' 2 ', ' 3 ', ' 4 '). ' * ' represents that number is removed by Yi Sima.

It's guaranteed that there'll be exactly one-to-recover the board.

Outputfor each test case, output one line containing Case #x:, where x is the test Case number (starting from 1). Then the output 4 lines with 4 characters each. Indicate the recovered board.

Sample input3****234141233214*243*312*421*134*41***3*2*414*2*

Sample outputcase #1:1432234141233214Case #2:1243431234212134Case #3:3412123423414123 Test Instructions: Sudoku, horizontal, vertical, each One-fourth block cannot have the same number. The puzzle: Open three array records horizontal, vertical, One-fourth blocks 1, 2, 3, 4 appear, Mark. Then enumerate each position, if there is no number, if (L[i][k]==0&&r[j][k]==0&&p[judge (i,j)][k]==0) to determine what to fill, if there are two can be filled, first skip.
#include <iostream>#include<cstdio>#include<algorithm>#include<cstring>using namespacestd;Chars[5][5];intans[5][5];intl[5][5];intr[5][5];intp[5][5];intJudgeintXinty) {    if(x<2&&y<2)return 1; if(x>=2&&y<2)return 3; if(x<2&&y>=2)return 2; if(x>=2&&y>=2)return 4;}voidsolve () { for(inti =0; i<4; i++)         for(intj =0; j<4; J + +) {L[i][ans[i][j]]=1; }     for(intj =0; j<4; J + +)         for(inti =0; i<4; i++) {R[j][ans[i][j]]=1; }     for(inti =0; i<4; i++)    {         for(intj =0; j<4; J + +) {P[judge (I,J)][ans[i][j]]=1; }    }    intFlag =1; intCount =0;  while(flag) {flag=0;  for(inti =0; i<4; i++)        {             for(intj =0; j<4; J + +) {Count=0; if(Ans[i][j])Continue;  for(intK =1; k<=4; k++)                {                    if(l[i][k]==0&&r[j][k]==0&&p[judge (I,J)][k]==0) Count++; }                if(Count = =1) {flag=1;  for(intK =1; k<=4; k++)                    {                        if(l[i][k]==0&&r[j][k]==0&&p[judge (I,J)][k]==0) {Ans[i][j]=K; L[I][K]=1; R[J][K]=1; P[judge (i,j)][k]=1; }                    }                }            }        }    }}intMain () {intT,kase =0; scanf ("%d",&t);  while(t--) {memset (L,0,sizeof(l)); Memset (R,0,sizeof(R)); memset (ans,0,sizeof(ans)); Memset (P,0,sizeof(p));  for(inti =0; i<4; i++) {scanf ("%s", S[i]); }         for(inti =0; i<4; i++)        {             for(intj =0; j<4; J + +)            {                if(S[i][j] = ='*') Ans[i][j] =0; ElseANS[I][J] = s[i][j]-'0';        }} solve (); printf ("Case #%d:\n",++Kase);  for(inti =0; i<4; i++)        {             for(intj =0; j<4; J + +) {printf ("%d", Ans[i][j]); } printf ("\ n"); }    }    return 0;}

HDU 5547 Violence

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.