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 ...
随机推荐
- H5 id选择器和class选择器
11-id选择器和class选择器 第一段文字 第二段文字 第三段文字 --> 第一段文字 第二段文字 第三段文字 <!DOCTYPE html> <html lang=&qu ...
- 小P的金字塔
题目描述 小P感到自己前几天太作了,于是非常有远见的决定为自己建立一座金字塔. 现在他有n种标准长方体的石头,每种石头只有两个,第i种石头是长宽高分别为Xi,Yi,Zi的长方体.由于整个工程只有小P一 ...
- 整数划分 poj3181
分析 因为n,m分别最大1000,100 所以结果会超过ll,要用两个来存大数的两部分 代码 #include<iostream> #include<algorithm> #i ...
- c++入门之类继承初步
继承是面向对象的一种很重要的特性,先来复习基类的基本知识: 先上一段代码: # ifndef TABLE00_H # define TABLE00_H # include "string&q ...
- PS提亮户外儿童照
(@摄影师延延)作品 调整完的图. 原图. 再看原图.好吧,这张照片明显欠曝了,蘑菇酱的小脸黑黑的.但是构图啊蘑菇酱的神情啊都不错捏.好在蘑菇妈是用raw格式拍,即刻Lightroom调整无压力. 1 ...
- Java Core - static关键字的理解
一.基本常识 二.关于main方法 我们最常见的static方法就是main方法,至于为什么main方法必须是static的,现在就很清楚了.因为程序在执行main方法的时候没有创建任何对象,因此只有 ...
- JMeter压测分布式部署
监控JMeter压力机的性能
- laravel创建项目
composer create-project --prefer-dist laravel/laravel=5.5.* blog
- AngularJS集合数据遍历显示
AngularJS集合数据遍历显示 <!DOCTYPE html> <html> <head> <meta charset="UTF-8" ...
- Spark源码编译,官网学习
这里以spark-1.6.0版本为例 官网网址 http://spark.apache.org/docs/1.6.0/building-spark.html#building-with-build ...