题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1426

题意很明确,让你解一个9*9的数独。

DFS即可。

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <functional> using namespace std; #define REP(i,n) for(int i(0); i < (n); ++i)
#define rep(i,a,b) for(int i(a); i <= (b); ++i)
#define dec(i,a,b) for(int i(a); i >= (b); --i)
#define for_edge(i,x) for(int i = H[x]; i; i = X[i]) #define LL long long
#define ULL unsigned long long
#define MP make_pair
#define PB push_back
#define FI first
#define SE second
#define INF 1 << 30 const int N = + ;
const int M = + ;
const int Q = + ;
const int A = + ; struct node{
int x, y;
} d[Q]; char ch; bool a[A][A];
int f[A][A], r[A][A], c[A][A], v[A][A];
bool rr[A][A], cc[A][A], vv[A][A];
int num; inline void print(){
rep(i, , ){rep(j, , ) printf("%d ", f[i][j]); printf("%d", f[i][]); putchar();}
} void dfs(int now){
if (now > num){ print(); return ;}
int x = d[now].x, y = d[now].y; rep(i, , ){
if (vv[v[x][y]][i]) continue;
if (cc[c[x][y]][i]) continue;
if (rr[r[x][y]][i]) continue;
f[x][y] = i;
vv[v[x][y]][i] = true;
cc[c[x][y]][i] = true;
rr[r[x][y]][i] = true;
dfs(now + );
f[x][y] = ;
vv[v[x][y]][i] = false;
cc[c[x][y]][i] = false;
rr[r[x][y]][i] = false;
} } int main(){
#ifndef ONLINE_JUDGE
freopen("test.txt", "r", stdin);
freopen("test.out", "w", stdout);
#endif rep(i, , ) rep(j, , ) v[i][j] = ;
rep(i, , ) rep(j, , ) v[i][j] = ;
rep(i, , ) rep(j, , ) v[i][j] = ;
rep(i, , ) rep(j, , ) v[i][j] = ;
rep(i, , ) rep(j, , ) v[i][j] = ;
rep(i, , ) rep(j, , ) v[i][j] = ;
rep(i, , ) rep(j, , ) v[i][j] = ;
rep(i, , ) rep(j, , ) v[i][j] = ;
rep(i, , ) rep(j, , ) v[i][j] = ;
rep(i, , ) rep(j, , ) r[i][j] = i, c[i][j] = j;
int Case = ; //rep(i, 1, 9){rep(j, 1, 9) printf("%d ", c[i][j]); putchar(10); }
while (~scanf("%c ", &ch)){
if (Case) puts(""); else Case = ;
// memset(a, false, sizeof a);
memset(f, , sizeof f);
memset(cc, false, sizeof cc);
memset(vv, false, sizeof vv);
memset(rr, false, sizeof vv);
memset(d, , sizeof d);
num = ;
if (ch == '?'){
f[][] = ;
d[++num].x = , d[num].y = ;
}
else{
int np = (int)ch - ;
f[][] = np;
cc[c[][]][np] = true;
vv[v[][]][np] = true;
rr[r[][]][np] = true;
} rep(cnt, , ){
scanf("%c ", &ch);
int x = (cnt - ) / + , y = (cnt - ) % + ;
if (ch == '?'){
f[x][y] = ;
d[++num].x = x, d[num].y = y;
}
else{
int np = (int)ch - ;
f[x][y] = np;
cc[c[x][y]][np] = true;
vv[v[x][y]][np] = true;
rr[r[x][y]][np] = true; }
//rep(i, 1, 9){rep(j, 1, 9) printf("%d ", f[i][j]); putchar(10);}
}
dfs();
} return ; }

HDU 1426 Sudoku Killer(搜索)的更多相关文章

  1. HDU 1426 Sudoku Killer(dfs 解数独)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1426 Sudoku Killer Time Limit: 2000/1000 MS (Java/Oth ...

  2. hdu 1426:Sudoku Killer(DFS深搜,进阶题目,求数独的解)

    Sudoku Killer Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  3. hdu 1426 Sudoku Killer (dfs)

    Sudoku Killer Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  4. hdu 1426 Sudoku Killer

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1426 #include<stdio.h> #include<math.h> #in ...

  5. hdu 1426 Sudoku Killer ( Dancing Link 精确覆盖 )

    利用 Dancing Link 来解数独 详细的能够看    lrj 的训练指南 和 < Dancing Links 在搜索中的应用 >这篇论文 Dancing Link 来求解数独 , ...

  6. HDU 1426 Sudoku Killer【DFS 数独】

    自从2006年3月10日至11日的首届数独世界锦标赛以后,数独这项游戏越来越受到人们的喜爱和重视. 据说,在2008北京奥运会上,会将数独列为一个单独的项目进行比赛,冠军将有可能获得的一份巨大的奖品— ...

  7. HDU 1426 Sudoku Killer (回溯 + 剪枝)

    本文链接:http://i.cnblogs.com/EditPosts.aspx?postid=5398818 题意: 给你一个 9*9 的矩阵,同一行相邻的两个元素用一个空格分开.其中1-9代表该位 ...

  8. HUD 1426 Sudoku Killer (DFS)

    链接 : Here! 思路 : 记录下所有 "?" , 出现的位置, 然后 $DFS$ 一下, 对于每个位置来说都可以填充 $9$ 种数值, 然后对于判断填充是否合法需要三个标记数 ...

  9. P - Sudoku Killer HDU - 1426(dfs + map统计数据)

    P - Sudoku Killer HDU - 1426 自从2006年3月10日至11日的首届数独世界锦标赛以后,数独这项游戏越来越受到人们的喜爱和重视. 据说,在2008北京奥运会上,会将数独列为 ...

随机推荐

  1. 【APUE】Chapter12 Thread Control

    今天看了APUE的Chapter12 Thread Control的内容,记录一下看书的心得与示例code. 这一章的内容是对Chapter11 Threads(见上一篇日志)的补充,大部分内容都是理 ...

  2. 每天一个Linux命令(8):chmod命令

    chmod命令用来变更文件或目录的权限. 权限范围的表示法如下: u   User,即文件或目录的拥有者:g  Group,即文件或目录的所属群组:o   Other,除了文件或目录拥有者或所属群组之 ...

  3. ASP.NET Core 认证与授权[2]:Cookie认证 (笔记)

    原文链接:https://www.cnblogs.com/RainingNight/p/cookie-authentication-in-asp-net-core.html 由于HTTP协议是无状态的 ...

  4. hnust 档案管理

    问题 E: 档案管理 时间限制: 1 Sec  内存限制: 128 MB提交: 274  解决: 105[提交][状态][讨论版] 题目描述 X老师管理着学校的档案室,经常会有其他的老师来档案室存文件 ...

  5. 破解navicat

    每次试用版也真的是烦,注册机试过一次后,又提示注册 果断选择其他方法 官网先下载一个正版 再下patchNavicat.exe 安装完navicat后直接点击patchNavicat 选择navica ...

  6. 雅礼集训 Day1 T3 画作 解题报告

    画作 题目描述 小\(\mathrm{G}\)的喜欢作画,尤其喜欢仅使用黑白两色作画. 画作可以抽象成一个\(r\times c\)大小的\(01\)矩阵.现在小\(\mathrm{G}\)构思好了他 ...

  7. 【CF Round 439 B. The Eternal Immortality】

    time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...

  8. java反射调用私有方法和修改私有属性

    //调用私有方法package com.java.test; public class PrivateMethod { private String sayHello(String name) { r ...

  9. 《c程序设计语言》读书笔记-第二个字符串任意一个在第一个字符串出现的位置,未出先返回-1

    #include <stdio.h> #include <string.h> #define Num 1000 int main() { int c,i,j = 0,m = 0 ...

  10. GitHub上README写法暨markdown语法解读

    原文: GitHub上README写法暨markdown语法解读 自从开始玩GitHub以来,就 越来越 感觉它有爱.最近对它的 README.md 文件颇为感兴趣.便写下这贴,帮助更多的还不会编写R ...