爆搜即可

/* ***********************************************
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. 授权给指定用户,使用navicat在其他ip都可以连接linux服务器上的mysql库

    grant all privileges on ao.* to 'tony'@'localhost' identified by '123456'; 在ao库中所有表. 同意 ,授权     给ton ...

  2. JS原型和原型链

        1 var decimalDigits = 2, 2 tax = 5; 3 4 function add(x, y) { 5 return x + y; 6 } 7 8 function su ...

  3. MySQL-测试卷一

    MySQL-测试卷一 一.单项选择题 1 下面不属于Msql数据库特点的是(  ) A. 免费使用  B.不能跨平台  C.开源软件  D.功能强大 2 定义表的一个字段, 要求能表示4位整数,2位小 ...

  4. git 更新分支

    git branch  本地分支 git branch test 创建分支 git pull origin fastboot 更新到最新版本 git branch -a  查看所有的分支,包括本地的和 ...

  5. poi 合并单元格、设置边框

    HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sheet = wb.createSheet(); //创建一个样式 HSSFCellStyle sty ...

  6. OpenGL ES着色器语言之语句和结构体(官方文档第六章)内建变量(官方文档第七、八章)

    OpenGL ES着色器语言之语句和结构体(官方文档第六章) OpenGL ES着色器语言的程序块基本构成如下: 语句和声明 函数定义 选择(if-else) 迭代(for, while, do-wh ...

  7. UIImagePickerController 相关

    UIImagePickerController是系统封装好的一个导航视图控制器,使用其开发者可以十分方便的进行相机相册相关功能的调用.UIImagePickerController继承于UINavig ...

  8. Override/implements methods 如何添加

    用过Eclipse 的ADT的都知道,要快速添加override或者implements方法,右键---Source---Override/Implements Method... 中文:右键---& ...

  9. Sublime Text 3 安装使用

    机器比较老,运行Pycharm等卡死,所以选择Sublime,非常流畅. 安装 版本3103 官网下载安装 注册码: —– BEGIN LICENSE —–Nicolas HennionSingle ...

  10. Codeforces 691A Fashion in Berland

    水题. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #includ ...