HDOJ5547 SudoKu
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5547
题目大意:填数独。。。
思路:爆搜
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
using namespace std;
bool row[][],col[][],siz[][];
int G[][];
bool flag;
int Num(int x,int y){
if(x<=&&y<=) return ;
if(x<=&&y>) return ;
if(x>&&y<=) return ;
if(x>&&y>) return ;
}
void dfs(int x,int y){
if(y>&&x==){
flag=true;
return ;
}
if(flag) return ;
if(y>) x++,y=;
if(G[x][y]) {
dfs(x,y+);
return;
}
if(flag) return ;
for(int i=;i<=;i++){
if(!row[x][i]&&!col[y][i]&&!siz[Num(x,y)][i]){
G[x][y]=i;
row[x][i]=col[y][i]=siz[Num(x,y)][i]=true;
dfs(x,y+);
if(flag) return ;
G[x][y]=;
row[x][i]=col[y][i]=siz[Num(x,y)][i]=false;
}
}
}
void init(){
flag=false;
memset(row,false,sizeof(row));
memset(col,false,sizeof(col));
memset(siz,false,sizeof(siz));
}
void solve(int T){
printf("Case #%d:\n",T);
init();
for(int x=;x<=;x++){
for(int y=;y<=;y++){
char tmp;
scanf(" %c",&tmp);
if(tmp=='*'){
G[x][y]=;
}
else {
G[x][y]=tmp-'';
int now=tmp-'';
row[x][now]=col[y][now]=siz[Num(x,y)][now]=true;
}
}
}
dfs(,);
for(int i=;i<=;i++){
for(int j=;j<=;j++){
printf("%d",G[i][j]);
}
printf("\n");
}
}
int main(){
int T;
//freopen("C:\\Users\\acm\\Desktop\\ACM\\out.txt","w",stdout);
scanf("%d",&T);
for(int i=;i<=T;i++) solve(i);
}
HDOJ5547 SudoKu的更多相关文章
- 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 ...
- Leetcode: Sudoku Solver
July 19, 2015 Problem statement: Write a program to solve a Sudoku puzzle by filling the empty cells ...
- Leetcode Valid Sudoku
Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board could be ...
随机推荐
- message:GDI+ 中发生一般性错误。
图片类型的文件保存的时候出了问题,可能是路径出错,也可能是保存到的文件夹不存在导致(发布项目的时候如果文件夹是空的,文件夹将不存在)
- Django 中的Form、ModelForm
一.ModelForm 源码 class ModelForm(BaseModelForm, metaclass=ModelFormMetaclass): pass def modelform_fact ...
- django 路由系统,数据库操作
一.修改配置 数据库 DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME':'dbname', 'USER': ...
- (Git 学习)Git SSH Key 创建步骤
首先感谢segmentfalut上的朋友对我帮助. 首先:查看你是否有../ssh 这个文件:怎么查看:找到你的git安装目录,在安装目录下查看是否./ssh,以我的为例: 在C盘/Users/11/ ...
- JS_左边栏菜单
需求: 要求实现左边栏菜单点击一下就弹开,其他的隐藏.再点击一下就隐藏. 最多只能有一个菜单的详细内容会显示出来. 三个菜单实现联动效果. 代码如下: 1 <!DOCTYPE html> ...
- 使用junit测试
package creeper; import java.util.Scanner; public class size { private static int intercePosition = ...
- [2017BUAA软工助教]个人项目测试结果
个人项目测试结果 标签(空格分隔): 未分类 9.29第一次测试结果 注:点击表头内相应项目可针对该项目进行排序 -c测试结果 INDEX NumberID -c 1 -c 5 -c 100 -c 5 ...
- Java使用Redis实现分布式锁来防止重复提交问题
如何用消息系统避免分布式事务? - 少年阿宾 - BlogJavahttp://www.blogjava.net/stevenjohn/archive/2018/01/04/433004.html [ ...
- 安全测试学习之bWAPP环境搭建
安装环境:window7+IIS+mysql+php bWAPP下载地址:https://sourceforge.net/projects/bwapp/files/bee-box/ ,直接点击Dow ...
- vue 短信验证
直接贴代码: HTML <div class="phone"> <div class="number"> <p class=&qu ...