[kuangbin]专题三 Dancing Links Sudoku POJ - 3074【精确覆盖】

【题目描述】
In the game of Sudoku, you are given a large 9 × 9 grid divided into smaller 3 × 3 subgrids. For example,
在Sudoku游戏中,你会得到一个大小为9 × 9的网格被分成更小的3 × 3的子网格。比如,
在这里插入图片描述
Given some of the numbers in the grid, your goal is to determine the remaining numbers such that the numbers 1 through 9 appear exactly once in (1) each of nine 3 × 3 subgrids, (2) each of the nine rows, and (3) each of the nine columns.
给你网格中的一些数字,你的任务是确定剩余的数字使得1到9都只出现一次(1)在9个3 × 3的子网格中(2)每一行(3)每一列

【输入】
The input test file will contain multiple cases. Each test case consists of a single line containing 81 characters, which represent the 81 squares of the Sudoku grid, given one row at a time. Each character is either a digit (from 1 to 9) or a period (used to indicate an unfilled square). You may assume that each puzzle in the input will have exactly one solution. The end-of-file is denoted by a single line containing the word “end”.
输入文件包含多个样例,每个样例包含一行81个字符,代表Sudoku网格的81个方格,一次给出一排。每个字符要么是1到9的数字要么是一个句号表示未填充的方格。你可以假设输入的每个谜题有且只有一个解。文件以一行单词"end"结束。

【输出】
For each test case, print a line representing the completed Sudoku puzzle.
对于每个样例,输出一行代表完整的Sudoku谜题。

【样例输入】

.2738..1..1...6735.......293.5692.8...........6.1745.364.......9518...7..8..6534.
......52..8.4......3...9...5.1...6..2..7........3.....6...1..........7.4.......3.
end

【样例输出】
527389416819426735436751829375692184194538267268174593643217958951843672782965341
416837529982465371735129468571298643293746185864351297647913852359682714128574936

题目链接:https://cn.vjudge.net/problem/POJ-3074

代码如下:

#include <iostream>
#include <cstring>
using namespace std;
static const int MAXN=9*9*9+10;
static const int MAXM=9*9*4+10;
static const int MAXNODE=MAXN*4+MAXM+10;
char g[MAXN];
struct DLX{
   
    int n,m,size;
    int U[MAXNODE],D[MAXNODE],L[MAXNODE],R[MAXNODE],Row[MAXNODE],Col[MAXNODE];
    int H[MAXN],S[MAXM];
    int ansd,ans[MAXN];
    void init(int _n,int _m)
    {
   
        n=_n;
        m=_m;
        for(int i=0;i<=m;i++)
        {
   
            S[i]=0;
            U[i]=D[i]=i;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值