Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu

Description

Sudoku is a very simple task. A square table with 9 rows and 9 columns is divided to 9 smaller squares 3x3 as shown on the Figure. In some of the cells are written decimal digits from 1 to 9. The other cells are empty. The goal is to fill the empty cells with decimal digits from 1 to 9, one digit per cell, in such way that in each row, in each column and in each marked 3x3 subsquare, all the digits from 1 to 9 to appear. Write a program to solve a given Sudoku-task. 

Input

The input data will start with the number of the test cases. For each test case, 9 lines follow, corresponding to the rows of the table. On each line a string of exactly 9 decimal digits is given, corresponding to the cells in this line. If a cell is empty it is represented by 0.

Output

For each test case your program should print the solution in the same format as the input data. The empty cells have to be filled according to the rules. If solutions is not unique, then the program may print any one of them.

Sample Input

1
103000509
002109400
000704000
300502006
060000050
700803004
000401000
009205800
804000107

Sample Output

143628579
572139468
986754231
391542786
468917352
725863914
237481695
619275843
854396127
/*/
数独 AC代码:
/*/
#include"iostream"
#include"cstdio"
#include"cstring"
#include"queue"
#include"string"
using namespace std;
int map[11][11],count,n;
bool F[11][11];
bool H[11][11];
bool L[11][11]; struct Node {
int x,y;
} node[100]; int MAP(int i,int j) {
if(i<=3&&j<=3)return 1;
else if(i<=3&&j<=6)return 2;
else if(i<=3&&j<=9)return 3;
else if(i<=6&&j<=3)return 4;
else if(i<=6&&j<=6)return 5;
else if(i<=6&&j<=9)return 6;
else if(i<=9&&j<=3)return 7;
else if(i<=9&&j<=6)return 8;
else if(i<=9&&j<=9)return 9;
} int DFS(int n) {
if(n>count) {
return 1;
}
for(int j=1; j<=9; j++) {
if(!H[node[n].x][j]&&!L[node[n].y][j]&&!F[MAP(node[n].x,node[n].y)][j]) {
H[node[n].x][j]=L[node[n].y][j]=F[MAP(node[n].x,node[n].y)][j]=1;
map[node[n].x][node[n].y]=j;
if(DFS(n+1))return 1;
H[node[n].x][j]=L[node[n].y][j]=F[MAP(node[n].x,node[n].y)][j]=0;
}
}
return 0;
} int main() {
int flag=0;
while(cin>>n) {
for(int i=1; i<=n; i++) {
memset(map,0,sizeof(map));
memset(H,0,sizeof(H));
memset(F,0,sizeof(F));
memset(L,0,sizeof(L));
count = 0;
for(int j=1; j<=9; j++)
for(int k=1; k<=9; k++) {
scanf("%1d",&map[j][k]);
if(map[j][k]==0) {
count++;
node[count].x=j;
node[count].y=k;
} else {
H[j][map[j][k]]=1;
L[k][map[j][k]]=1;
F[MAP(j,k)][map[j][k]]=1;
}
}
DFS(1);
for(int j=1; j<=9; j++) {
for(int k=1; k<=9; k++)
cout<<map[j][k];
cout<<endl;
} }
}
return 0;
}

ACM : POJ 2676 SudoKu DFS - 数独的更多相关文章

  1. poj 2676 Sudoku ( dfs )

    dfs 用的还是不行啊,做题还是得看别人的博客!!! 题目:http://poj.org/problem?id=2676 题意:把一个9行9列的网格,再细分为9个3*3的子网格,要求每行.每列.每个子 ...

  2. 深搜+回溯 POJ 2676 Sudoku

    POJ 2676 Sudoku Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 17627   Accepted: 8538 ...

  3. POJ 2676 Sudoku (数独 DFS)

      Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 14368   Accepted: 7102   Special Judg ...

  4. POJ 2676 - Sudoku - [蓝桥杯 数独][DFS]

    题目链接:http://poj.org/problem?id=2676 Time Limit: 2000MS Memory Limit: 65536K Description Sudoku is a ...

  5. POJ - 2676 Sudoku 数独游戏 dfs神奇的反搜

    Sudoku Sudoku is a very simple task. A square table with 9 rows and 9 columns is divided to 9 smalle ...

  6. 搜索 --- 数独求解 POJ 2676 Sudoku

    Sudoku Problem's Link:   http://poj.org/problem?id=2676 Mean: 略 analyse: 记录所有空位置,判断当前空位置是否可以填某个数,然后直 ...

  7. ACM: ICPC/CCPC Sudoku DFS - 数独

    Sudoku Time Limit : 3000/1000ms (Java/Other)   Memory Limit : 65535/65535K (Java/Other) Total Submis ...

  8. POJ 2676 Sudoku (DFS)

    Sudoku Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 11694   Accepted: 5812   Special ...

  9. DFS POJ 2676 Sudoku

    题目传送门 题意:数独问题,每行每列以及每块都有1~9的数字 分析:一个一个遍历会很慢.先将0的位子用vector存起来,然后用rflag[i][num] = 1 / 0表示在第i行数字num是否出现 ...

随机推荐

  1. Object-C目录

    Object学习目录: 1.OC概述 2.OC第一个应用程序 3.OC之类和对象(属性.方法,点语法) 4.OC之类的扩充(self,super关键字.继承.构造函数等)   5.OC之分类Categ ...

  2. 悲剧啊!Mysql的上古BUG!!!

    导读 这是MySQL8.0修复的上古bug之一,在2003年由Percona的CEO(当时应该还没Percona吧)提出的bug#199,光看这bug号就扑面而来一股上古时代的沧桑气息. 问题的本质在 ...

  3. setprecision **fixed

    #include <iostream> #include <iomanip> using namespace std; int main( void ) { const dou ...

  4. linux Mint18 backspace怎么不能连续删除

    打开菜单--->首选项--->键盘,如下图所示: 打开启用重复按键即可,就可以随心所欲的连续删除,连续移动光标了

  5. selenium web driver 实现截图功能

    在验证某些关键步骤时,需要截个图来记录一下当时的情况 Webdriver截图时,需要引入 import java.io.File; import java.io.IOException; import ...

  6. sgu 240 Runaway (spfa)

    题意:N点M边的无向图,边上有线性不下降的温度,给固定入口S,有E个出口.逃出去,使最大承受温度最小.输出该温度,若该温度超过H,输出-1. 羞涩的题意 显然N*H的复杂度dp[n][h]表示到达n最 ...

  7. rsync参数及通信

    rsync 支持:  本机数据 <-------> 远程数据/本地数据 意义:  支持增量拷贝 --> 备份,节省带宽,时间   rsync -avL 一.常用选项  ******* ...

  8. js 实时监听input中值变化

    注意:用到了jquery需要引入jquery.min.js. 需求: 1.每个地方需要分别打分,总分为100; 2.第一个打分总分为40; 3.第二个打分总分为60. 注意:需要判断null.&quo ...

  9. "飞机大战"游戏_Java实现_详细注释

    1 package cn.xiaocangtian.Util; import java.awt.Frame; import java.awt.Graphics; import java.awt.Ima ...

  10. Linux中杀不死的进程

    前段时间,一哥们,去杀Linux服务器的进程,发现kill命令失灵了,怎么杀都杀不死. 然后上网查了下资料,原来是要被杀的进程,成为了僵尸进程. 僵尸进程的查看方法: 利用命令ps,可以看到有标记为Z ...