POJ 2676 Sudoku
Time Limit: 2000MS | Memory Limit: 65536K | |||
Total Submissions: 12005 | Accepted: 5984 | Special Judge |
Description

Input
Output
Sample Input
1
103000509
002109400
000704000
300502006
060000050
700803004
000401000
009205800
804000107
Sample Output
143628579
572139468
986754231
391542786
468917352
725863914
237481695
619275843
854396127
题目大意:数独填空。
解题方法:搜索。
#include <stdio.h>
#include <iostream>
#include <string.h>
using namespace std; typedef struct
{
int x;
int y;
}Point; Point p[]; char Maze[][];
int nCount = ;
bool bfind = false; bool Judge1(int row, int n)
{
for (int i = ; i < ; i++)
{
if (Maze[row][i] == n)
{
return false;
}
}
return true;
} bool Judge2(int col, int n)
{
for (int i = ; i < ; i++)
{
if (Maze[i][col] == n)
{
return false;
}
}
return true;
} bool Judge3(int row, int col, int n)
{
row = row / ;
col = col / ;
for (int i = row * ; i < row * + ; i++)
{
for (int j = col * ; j < col * + ; j++)
{
if (Maze[i][j] == n)
{
return false;
}
}
}
return true;
} void DFS(int Step)
{
if (Step == nCount && !bfind)
{
bfind = true;
for (int i = ; i < ; i++)
{
for (int j = ; j < ; j++)
{
printf("%d", Maze[i][j]);
}
printf("\n");
}
}
for (int i = ; i <= ; i++)
{
if (Judge1(p[Step].x, i) && Judge2(p[Step].y, i) && Judge3(p[Step].x, p[Step].y, i) && !bfind && Maze[p[Step].x][p[Step].y] == )
{
Maze[p[Step].x][p[Step].y] = i;
DFS(Step + );
Maze[p[Step].x][p[Step].y] = ;
}
}
} int main()
{
int nCase;
char str[];
scanf("%d", &nCase);
memset(Maze, , sizeof(Maze));
while(nCase--)
{
nCount = ;
bfind = false;
for (int i = ; i < ; i++)
{
scanf("%s", str);
for (int j = ; j < ; j++)
{
Maze[i][j] = str[j] - '';
if (Maze[i][j] == )
{
p[nCount].x = i;
p[nCount].y = j;
nCount++;
}
}
}
DFS();
}
return ;
}
POJ 2676 Sudoku的更多相关文章
- 深搜+回溯 POJ 2676 Sudoku
POJ 2676 Sudoku Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 17627 Accepted: 8538 ...
- ACM : POJ 2676 SudoKu DFS - 数独
SudoKu Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu POJ 2676 Descr ...
- 搜索 --- 数独求解 POJ 2676 Sudoku
Sudoku Problem's Link: http://poj.org/problem?id=2676 Mean: 略 analyse: 记录所有空位置,判断当前空位置是否可以填某个数,然后直 ...
- POJ 2676 Sudoku (数独 DFS)
Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 14368 Accepted: 7102 Special Judg ...
- POJ 2676 - Sudoku - [蓝桥杯 数独][DFS]
题目链接:http://poj.org/problem?id=2676 Time Limit: 2000MS Memory Limit: 65536K Description Sudoku is a ...
- poj 2676 Sudoku ( dfs )
dfs 用的还是不行啊,做题还是得看别人的博客!!! 题目:http://poj.org/problem?id=2676 题意:把一个9行9列的网格,再细分为9个3*3的子网格,要求每行.每列.每个子 ...
- POJ 2676 Sudoku(深搜)
Sudoku Time Limit : 4000/2000ms (Java/Other) Memory Limit : 131072/65536K (Java/Other) Total Submi ...
- POJ 2676 Sudoku (DFS)
Sudoku Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 11694 Accepted: 5812 Special ...
- POJ - 2676 Sudoku 数独游戏 dfs神奇的反搜
Sudoku Sudoku is a very simple task. A square table with 9 rows and 9 columns is divided to 9 smalle ...
随机推荐
- [C++] C/C++结构体的区别
C/C++结构体的区别 >_<:C中的结构体和C++中结构体的不同之处: 在C中的结构体只能自定义数据类型,结构体中不允许有函数,而C++中的结构体可以加入成员函数. >_<: ...
- [matlab] MATLAB 界面编程 傻瓜教程
>_<:在 MATLAB 的命令窗口(Command Window)中运行 guide 命令,来打开 GUIDE 界面,如下: >_<:然后,选择空模板(Blang GUI), ...
- 通过JavaScript脚本实现验证码自动输入
很多网站在用户进行某次点击,比如在线购物确认购买时,会要求用户输入验证码,这在一般情况下也没啥问题,但在用户需要频繁购买或是抢购时就很讨厌了.其实网站的验证码一般是由JS脚本生成的,因此也可以通过编写 ...
- Zabbix学习笔记一:基本安装与配置
1.下载安装 http://120.52.73.43/tenet.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/3.0.1/za ...
- paip.性能跟踪profile原理与架构与本质-- python扫带java php
paip.性能跟踪profile原理与架构与本质-- python扫带java php ##背景 弄个个输入法音标转换atiEnPH工具,老是python性能不的上K,7k记录浏览过k要30分钟了. ...
- paip.提升效率--僵尸代码的迷思
paip.提升效率--僵尸代码的迷思 僵尸代码是指你的代码库里被注释掉的那部分代码, 很少去使用它,就像僵尸一样, 看雷kill-the-zombies-in-your-code ========== ...
- jsp实现验证码
在web开发领域里面,验证码是一个比较常见的功能,而归根到底,验证码其实就是一组随机数,或者是一个随机算术 一.基本知识 1.为什么需要验证码? 验证码,很多时候出现在注册页面或者登陆界面,在这些页面 ...
- ListView、PullToRefreshListView滑动加载可见item
最近用的了PullToRefreshListView框架,也在listView中加载图片,对于滑动加载可见item,网上找了一些相关文档,但都不太合适,如:http://blog.csdn.net/z ...
- IBM的IT战略规划方法论
IBM的IT战略规划方法论 http://wenku.baidu.com/view/42489e21aaea998fcc220e92.html?re=view http://wenku.baidu.c ...
- Activiti保存流程图时diagrms中没有生成png解决办法
window ——> preferences——>activiti——>save——>选中create process definition image when saving ...