UESTC 1222 Sudoku
爆搜即可
/* ***********************************************
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 ...
随机推荐
- Opencv2系列学习笔记10(提取连通区域轮廓) 另一个
http://blog.csdn.net/lu597203933/article/details/17362457 连通区域指的是二值图像中相连像素组成的形状.而内.外轮廓的概念及opencv1中如何 ...
- 编辑器phpstrom的快捷键修改
file->setting-->查找 keymap -->查找 format 格式化代码 ctrl+alt +L appearance-->外观-->显示行号
- oc知道经纬度求位置
CLLocation *newLocation = [locations lastObject]; CLGeocodeCompletionHandler handler = ^(NSArray *pl ...
- 设置ubuntu 默认不启动图形界面
设置ubuntu 默认不启动图形界面 一. 编辑文件/etc/X11/default-display-manager 如果值为/usr/sbin/gdm,则进入图形界面如果值为false,则进入控制台 ...
- 二维 ST POJ 2019
题目大意:给你一个n*n的矩阵,每次给你一个点(x,y),以其为左上角,宽度为b的矩阵中最小的数值和最大数值的差是多少? 一共k个询问. 思路:简单的二维st. 定义dp(i,j,k,L)表示以(i ...
- E212:无法打开并写入文件
用vi编辑文件是 老师出现这样的错误 有些文件 需要root权限才能修改 切换成root权限就行了
- PHP基本类型操作
//关键字对大小写不敏感echo ('hello world!<br>');ECho ('hello world<br>');eCho ('hello world<br& ...
- 关于JAVA插入Mysql数据库中文乱码问题解决方案
方案一:在创建client的时候,指定使用的编码方式 具体如下: conn = DriverManager.getConnection("jdbc:mysql://localhost:33 ...
- 详细的SQL中datediff用法
DATEDIFF 函数 [日期和时间] 功能返回两个日期之间的间隔. 语法DATEDIFF ( date-part, date-expression-1, date-expression-2 ) da ...
- undefined与null
undefined 声明的变量尚未初始化 null 对象尚未存在 eg: var a; console.log(typeof a); 输出undefined var b= document.getEl ...