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 marquee标签
39-marquee标签 内容 属性: direction: 设置滚动方向 left/right/up/down scrollamount: 设置滚动速度, 值越大就越快 loop: 设置滚动次数, ...
- [2019BUAA软工助教]答黄杉同学
[2019BUAA软工助教]答黄杉同学 一.答黄杉同学 011-黄衫博客 我当然不否认软件工程的各种博客是有一定作用的,但是相信大多数人对诸如例会博客并没有什么热情(不过似乎也没有什么其他方法保证团队 ...
- 牛客练习赛 A题 筱玛的快乐
链接:https://ac.nowcoder.com/acm/contest/342/A来源:牛客网 筱玛的快乐 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 524288K,其他语 ...
- p33自然同态
如何理解两个划线的地方 1.因为,所以所以ker(π|_H)=kerπ∩H=N∩H 2.gN=Ng,对任意的g 属于G 因为 N被H/N 包含 也对任意的 g 属于 HN成立 ...
- debian6保存iptables规则
iptables规则不保存,一旦机器重启规则就清空了,所以需要保存: iptables-save >/etc/iptables-script vi /etc/rc.local 然后在文件中输入: ...
- 从Mongo导出数据库到Excel
在MongoDB的安装目录的bin文件夹下打开命令行: ./mongoexport -d kugou_db -c songs -f rank,singer,song,time --type=csv - ...
- 【Python3练习题 002】企业发放的奖金根据利润提成
# [Python练习题 002]企业发放的奖金根据利润提成.# 利润(I)低于或等于10万元时,奖金可提10%:利润高于10万元,低于20万元时,低于10万元的部分按10%提成,高于10万元的部分, ...
- IdentityServer4【QuickStart】之设置和概述
设置和概述 有两个基本的方式来开启一个新的IdentityServer项目: 从头开始 从asp.net Identity模板开始 如果你从头开始,我们提供了一些基于内存中构建的存储,所以你不必一开始 ...
- Tomcat 目录结构以及基本配置
1 Tomcat 目录层次结构 ① bin:存放启动和关闭tomcat 的脚本文件② conf: 存放配置文件 server.xml:该文件用于配置和server 相关的信息,比如tomcat 启动端 ...
- picker-view 组件 的value失效问题
首先检查是不是漏了绑定关系 组件内 组件引用 如过还不行就用下面的方法,顺序问题 在给暂时列表赋值之后再对value赋值