爆搜即可

/* ***********************************************
author :
email :523689985@qq.com
created time :2015/12/1 15:46:23
file name :main.cpp
************************************************ */ #include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std; const int maxn=;
int r[maxn][maxn],c[maxn][maxn],q[maxn][maxn];
int T;
char Map[maxn][maxn];
int ans[maxn][maxn];
int Qx[maxn*maxn],Qy[maxn*maxn];
int tot;
int flag; int F(int x,int y)
{
if(x==||x==)
{
if(y<=) return ;
else return ;
}
else
{
if(y<=) return ;
else return ;
}
} void dfs(int Now)
{
if(Now==tot)
{
flag=;
return;
}
int nowX=Qx[Now];
int nowY=Qy[Now];
for(int i=;i<=;i++)
{
if(r[nowX][i]==&&c[nowY][i]==&&q[F(nowX,nowY)][i]==)
{
r[nowX][i]=c[nowY][i]=q[F(nowX,nowY)][i]=;
ans[nowX][nowY]=i;
dfs(Now+);
if(flag) return;
r[nowX][i]=c[nowY][i]=q[F(nowX,nowY)][i]=;
}
}
} int main()
{
scanf("%d",&T);
for(int Case=;Case<=T;Case++)
{
memset(r,,sizeof r);
memset(c,,sizeof c);
memset(q,,sizeof q);
tot=; flag=;
for(int i=;i<;i++) scanf("%s",Map[i]);
for(int i=;i<;i++)
{
for(int j=;j<;j++)
{
if(Map[i][j]=='*')
{
ans[i][j]=-;
Qx[tot]=i;
Qy[tot]=j;
tot++;
}
else
{
ans[i][j]=Map[i][j]-'';
r[i][ans[i][j]]=;
c[j][ans[i][j]]=;
q[F(i,j)][ans[i][j]]=;
}
}
}
flag=;
dfs();
printf("Case #%d:\n",Case);
for(int i=;i<;i++)
{
for(int j=;j<;j++)
printf("%d",ans[i][j]);
printf("\n");
}
}
return ;
}

UESTC 1222 Sudoku的更多相关文章

  1. ACM学习历程—UESTC 1222 Sudoku(矩阵)(2015CCPC H)

    题目链接:http://acm.uestc.edu.cn/#/problem/show/1226 题目大意就是构造一个行列和每个角的2*2都是1234的4*4矩阵. 用dfs暴力搜索,不过需要每一步进 ...

  2. UESTC - 1222 Sudoku(深搜)

    Yi Sima was one of the best counselors of Cao Cao. He likes to play a funny game himself. It looks l ...

  3. Leetcode 笔记 36 - Sudoku Solver

    题目链接:Sudoku Solver | LeetCode OJ Write a program to solve a Sudoku puzzle by filling the empty cells ...

  4. [LeetCode] Sudoku Solver 求解数独

    Write a program to solve a Sudoku puzzle by filling the empty cells. Empty cells are indicated by th ...

  5. [LeetCode] Valid Sudoku 验证数独

    Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board could be ...

  6. LeetCode 36 Valid Sudoku

    Problem: Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board ...

  7. 【leetcode】Valid Sudoku

    题目简述: Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board cou ...

  8. ACM : POJ 2676 SudoKu DFS - 数独

    SudoKu Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu POJ 2676 Descr ...

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

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

随机推荐

  1. JRE与JDK

    Java源代码是以*.java的纯文本文件,可以使用任何文本编辑器编写,但不可以执行. JDK是Java语言的开发包,可以将*.java文件编译成可执行Java文件. 可执行Java程序需要JVM才可 ...

  2. Eclipse如何自定义format代码

  3. Unable to chmod

    不能改变权限 Unable to chmod /system/build.prop.: Read-only file system 解决方式: before chmod: Code: mount -o ...

  4. ProgressDialog

    几个方法介绍: 1.setMax() 设置对话框中进度条的最大值. 2.setTile() 设置标题. 3.setProgressStyl() 设置对话框中进度条的样式.例如:环形和水平. 参数: P ...

  5. sql关键字过滤C#方法

    /// <summary> ///SQL注入过滤 /// </summary> /// <param name="InText">要过滤的字符串 ...

  6. lepus bug

    ------------------------------------------------BUG fix-------------------------------------------- ...

  7. 巧妙使用Contains()方法查找一个数是否在某堆数中

    问题:要判断用户输入的一个数,或者是程序里方法的一个参数的值,或者是一个变量的值是否在某堆数中. 简洁写法:把这堆数放在list中,使用list的Contains()方法检查list是否包含这个数,取 ...

  8. perfect-scrollbar示例

    <!DOCTYPE html> <html> <head> <title>perfect-scrollbar - www.97zzw.com -97站长 ...

  9. NSAttributedString in Swift

    转载自: https://www.invasivecode.com/weblog/attributed-text-swift/   I have been talking quite a lot in ...

  10. 在CDockablePane中嵌入CFormView

    CDockablePane中嵌入CFormView与嵌入CDialogEx稍有不同,差异主要体现在CFormView类本身与CDialogEx类的不同上,CDockablePane层面的操作完全相同. ...