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 ...
随机推荐
- 关于oracle设置主键自增的问题
关于orcale设置主键自增的问题 关于主键Oracle中并没有提供一个直接的语句设置,对于这个oralce一般都是用序列和触发器来实现 一下又两种方法来实现 一 ,不使用触发器 创建序列: crea ...
- python文件读和写
fileHandle = open ( 'G:/qqfile/1.txt','w' )fileHandle.write('abcd')#写文件 地址要用反斜杠fileHandle.close() fi ...
- SOAP UI-----测webservice接口
webservice的请求报文和返回报文都是xml格式的. 使用soapui.storm对webservice接口进行测试,postman无法测. http://www.webxml.com.cn/W ...
- Java面试题详解三:比较器
一,Comparable和Comparator1.Comparable可以认为是一个内比较器,实现了Comparable接口的类有一个特点,就是这些类是可以和自己比较.Comparable接口中只有一 ...
- Bridge (br0) Network on Linux
动手实践虚拟网络 - 每天5分钟玩转 OpenStack(10) - CloudMan - 博客园https://www.cnblogs.com/CloudMan6/p/5296573.html li ...
- Nginx三部曲(1)基础
我们会告诉你 Nginx 是如何工作的,其背后的概念有哪些,以及如何优化它以提升应用程序的性能.还会告诉你如何安装,如何启动.运行. 这个教程包括三节: 基础概念——你可以了解命令(directive ...
- myecplise ssh项目配置上遇到的问题
版本:spring3.1+hib4.1+struts2.1 学习项目使用此版本运行时,总是会遇到各样的错误,在这里做一下记录. 问题1:log4j相关 spring的web项目,执行时报错: 信息: ...
- php的amqp扩展 安装(windows) rabbitmq学习篇
因为RabbitMQ是由erlang语言实现的,所以先要安装erlang环境erlang 下载安装 http://www.erlang.org/download.htmlrabbitmq 下载安装 h ...
- java学习之—递归
/** * 递归 * Create by Administrator * 2018/6/20 0020 * 上午 9:41 **/ public class TriangleApp { static ...
- 如何使用apache自带的ab压力测试工具
ab是apache自带的一个很好用的压力测试工具,当安装完apache的时候,就可以在bin下面找到ab 1 我们可以模拟100个并发用户,对一个页面发送1000个请求 ./ab -n1000 -c1 ...