爆搜即可

/* ***********************************************
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. cmd 下登陆ftp及相关操作

    cmd 下登陆ftp及相关操作 2011-08-09 20:34:28|  分类: 小技巧|字号 订阅 一.举例 假设FTP地址为“ 61.129.83.39”(大家试验的时候不要以这个FTP去试,应 ...

  2. Storm官方帮助手册翻译(下)

    使用其他语言编写Bolt Bolt可以使用任意语言编写.用另外一种语言编写Bolt来作为子进程运行.Storm会在标准输入输出的基础上使用Json来与子进程通信.通信协议之需要一个100行的适配器库, ...

  3. servlet第2讲(下集)----创建servlet实例(继承HttpServlet)

  4. karma+jasmine自动化测试

    1.安装nodejs,进入项目目录 2.安装karma和相关插件 npm install karma --save-dev npm install karma-jasmine karma-chrome ...

  5. HDU 5963 博弈

    http://acm.hdu.edu.cn/showproblem.php?pid=5963 题目大意:中文题 思路:看ICPC camp好了,简单易懂:https://async.icpc-camp ...

  6. dp + 组合数 Codeforces Beta Round #9 (Div. 2 Only) D

    http://codeforces.com/problemset/problem/9/D 题目大意:给你一个二叉树和n个数字,满足左小右大,能形成多少种不同的二叉树 思路:定义dp[i][j]表示目前 ...

  7. 概率好题 Light OJ 1027

    题目大意:你在迷宫里,有n扇门,每个门有一个val,这个val可正可负,每次通过一扇门需要abs(x)分钟,如果这个门的val是正的,那么就直接出了迷宫,否则回到原地,问出去迷宫的期望是多少? 思路: ...

  8. Qt之操作系统环境

    来源:http://blog.sina.com.cn/s/blog_a6fb6cc90102uy9k.html Qt中操作系统环境,官方解释如下: QStringList QProcess::syst ...

  9. icon大小

    ldpi mdpi hdpi xhdpi xxhdpi

  10. 3.1 cron表达式

    1.Cron在线生成网址:      http://cron.qqe2.com/   http://www.pdtools.net/tools/becron.jsp#cron 2.Cron 概要 3. ...