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 ...
随机推荐
- jquery判断<inpur type="checkbox" checked>是否被选择
建议使用 $('#isCheck').attr('checked') 这样的,利于判断 console.log($('#isCheck').prop('checked')); 可以看出prop当che ...
- 动态规划-LIS最长上升子序列
优化链接 [https://blog.csdn.net/George__Yu/article/details/75896330] #include<stdio.h> #include< ...
- OSS网页上传和断点续传(终结篇)
有了之前OSS网页上传和断点续传(OSS配置篇)和(STSToken篇),其万事俱备只欠东风啦,此终结篇即将展示OSS上传文件及断点续传的无限魅力... 网络卡顿.延迟能续传吗?能! 关了浏览器,还能 ...
- 如果需要精确的答案,请避免使用float和double
Java中的简单浮点数类型float和double不能够进行运算.不光是Java,在其它很多编程语言中也有这样的问题.在大多数情况下,计算的结果是准确的,但是多试几次(可以做一个循环)就可以试出类似上 ...
- 会议室预订系统(meeting room booking system)
一.mrbs mrbs:(meeting room booking system) 二.效果 三.models from django.db import models # Create your ...
- hdu1421_搬寝室
题目:搬寝室 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1421 #include<stdio.h> #include<algor ...
- Eclipse的DEgub调试乱跳
去掉勾选,是软件的BUG
- CART算法与剪枝原理
参考:https://blog.csdn.net/u014688145/article/details/53326910 知乎:https://www.zhihu.com/question/22697 ...
- KVM+QEMU虚拟化概念
概念: KVM,即Kernel-basedvirtual machine,由redhat开发,是一种开源.免费的虚拟化技术.对企业来说,是一种可选的虚拟化解决方案. 定义:基于Linux内核的虚拟机 ...
- 百度云虚拟主机配置 Thinkphp5.1
材料 服务器:百度云虚拟主机(nginx+php7.0+linux) Thinkphp 5.1 问题 百度云默认目录为/webroot,但是我们的需求是将项目存放到/webroot/public下面. ...