爆搜即可
/* ***********************************************
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的更多相关文章
-
ACM学习历程—UESTC 1222 Sudoku(矩阵)(2015CCPC H)
题目链接:http://acm.uestc.edu.cn/#/problem/show/1226 题目大意就是构造一个行列和每个角的2*2都是1234的4*4矩阵. 用dfs暴力搜索,不过需要每一步进 ...
-
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 ...
-
Leetcode 笔记 36 - Sudoku Solver
题目链接:Sudoku Solver | LeetCode OJ Write a program to solve a Sudoku puzzle by filling the empty cells ...
-
[LeetCode] Sudoku Solver 求解数独
Write a program to solve a Sudoku puzzle by filling the empty cells. Empty cells are indicated by th ...
-
[LeetCode] Valid Sudoku 验证数独
Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board could be ...
-
LeetCode 36 Valid Sudoku
Problem: Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board ...
-
【leetcode】Valid Sudoku
题目简述: Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board cou ...
-
ACM : POJ 2676 SudoKu DFS - 数独
SudoKu Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu POJ 2676 Descr ...
-
ACM: ICPC/CCPC Sudoku DFS - 数独
Sudoku Time Limit : 3000/1000ms (Java/Other) Memory Limit : 65535/65535K (Java/Other) Total Submis ...
随机推荐
-
kali安装java1.8
0x01 下载 首先,去官方网站下载JDK1.8对应的版本 http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads ...
-
scrollba美化
1.overflow内容溢出时的设置(设定被设定对象是否显示滚动条) overflow-x水平方向内容溢出时的设置 overflow-y垂直方向内容溢出时的设置 以上三个属性设置的值 ...
-
Java获得UTC时间
在Java语言中,您可以通过java.util.Calendar类取得一个本地时间或者指定时区的时间实例,如下: 取得本地时间: java.util.Calendar cal = java.util. ...
-
深入浅出-iOS函数式编程的实现 &;&; 响应式编程概念
简介 本篇主要回顾一下--iOS函数式编程 && 响应式编程概念 ,如何一步步实现函数式编程的过程,对阅读Masonry && SnapKit源码有一定的帮助. 配图 ...
-
Buns(dp+多重背包)
C. Buns time limit per test 2 seconds memory limit per test 256 megabytes input standard input outpu ...
-
php checkbox 从数据库读取和写入
checkbox将选中的值写入数据库中,在修改的时候如何从数据库中读取并设定Checkbox的状态 1.写入数据库提交后因为你的rol是数组,所以可以使用$_POST获取 PHP code ? 1 ...
-
eclipse C 开发 Stm32
版权声明:本文为博主原创文章,未经博主允许不得转载. 1.下载eclipse需要的运行环境,JDK/JRE. 在http://wiki.eclipse.org/Eclipse/Installation ...
-
实现一个ordeeddict
class MyOrderdict(): def __init__(self, mydict): self._cur = 0 self._mykeys = [] self._myvalues = [] ...
-
delphi EncdDecd.pas单元中Encoding方法出现#$D#$A的解决方法
例如: s:= 'http://detail.tmall.com/item.htm?id=45545826531&abbucket=_AB-M129_B17&acm=03130.100 ...
-
【源代码R3】移植一份LARGE_INTEGER转时间的代码
本代码来自ReactOS-0.4.0\lib\rtl\time.c中的函数RtlTimeToTimeFields(IN PLARGE_INTEGER Time, OUT PTIME_FIELDS Ti ...