Problem Description
Yi Sima was one of the best counselors of Cao Cao. He likes to play a funny game himself. It looks like the modern Sudoku, but smaller. Actually, Yi Sima was playing it different. First of all, he tried to generate a × board with every row contains to , every column contains to . Also he made sure that if we cut the board into four × pieces, every piece contains to . Then, he removed several numbers from the board and gave it to another guy to recover it. As other counselors are not as smart as Yi Sima, Yi Sima always made sure that the board only has one way to recover. Actually, you are seeing this because you've passed through to the Three-Kingdom Age. You can recover the board to make Yi Sima happy and be promoted. Go and do it!!! Input
The first line of the input gives the number of test cases, T(≤T≤). T test cases follow. Each test case starts with an empty line followed by lines. Each line consist of characters. Each character represents the number in the corresponding cell (one of '', '', '', ''). '*' represents that number was removed by Yi Sima. It's guaranteed that there will be exactly one way to recover the board. Output
For each test case, output one line containing Case #x:, where x is the test case number (starting from ). Then output lines with characters each. indicate the recovered board. Sample Input **** *
*
*
*
**
***
*
** Sample Output
Case #: Case #:
1243
4312
3421
2134
Case #:
3412
1234
2341
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
using namespace std;
#define N 50
#define met(a,b) memset(a,b,sizeof(a));
vector<vector<int> >Q;
struct node
{
int x,y;
}s[N];
char str[N][N];
int te;
int pan(int k,int n)
{
for(int i=;i<;i++)///判断这个点的这一列是否出现过数字k
{
if(i==s[n].x)
continue;
if(str[i][s[n].y]-''==k)
return ;
}
for(int i=;i<;i++)///判断这个点的这一行是否出现过数字k
{
if(i==s[n].y)
continue;
if(str[s[n].x][i]-''==k)
return ;
}
for(int i=;i<=;i++)///判断包含这个点的2*2角落是否出现过数字k
{
for(int j=;j<=;j++)
{
int xx=s[n].x/*+i;
int yy=s[n].y/*+j;
if(xx==s[n].x && yy==s[n].y)
continue;
if(str[xx][yy]-''==k)
return ;
}
}
return ;
}
void dfs(int m)
{
if(te==m)
{
for(int i=;i<;i++)
puts(str[i]);
return ;
}
for(int i=;i<=;i++)
{
if(pan(i,m))///判断数字i是否可以放在这个点上
{
str[s[m].x][s[m].y]=i+'';
dfs(m+);
str[s[m].x][s[m].y]='';
}
}
return ;
}
int main()
{
int t,con=;
scanf("%d",&t);
while(t--)
{
for(int i=;i<;i++)
{
scanf("%s",str[i]);
}
te=;
for(int i=;i<;i++)
{
for(int j=;j<;j++)
{
if(str[i][j]=='*')///找哪几个点需要填数,一共多少个
{
s[te].x=i;
s[te].y=j;
str[i][j]='';
te++;
}
}
}
printf("Case #%d:\n",con++);
dfs();
}
return ;
}

(hdu)5547 Sudoku (4*4方格的 数独 深搜)的更多相关文章

  1. HDU - 5547 Sudoku(数独搜索)

    Description Yi Sima was one of the best counselors of Cao Cao. He likes to play a funny game himself ...

  2. HDU 5547 Sudoku(DFS)

    题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=5547 题目: Sudoku Time Limit: 3000/1000 MS (Java/Others ...

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

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

  4. HDU 5547 Sudoku (暴力)

    题意:数独. 析:由于只是4*4,完全可以暴力,要注意一下一些条件,比如2*2的小方格也得是1234 代码如下: #pragma comment(linker, "/STACK:102400 ...

  5. [NOIP2009]靶形数独 深搜+枝杈优化

    这道题,又是一位玄学搜索...... 我是用的蜗牛序搜的(顾名思义,@,这么搜),我正着搜80然后一反转比原来快了几十倍........一下AC....... 我的思路是这样的话我们可以从内到外或者从 ...

  6. hdu 1045 要求全部逐一搜索完的深搜

    #include<stdio.h> #include<string.h> int visit[10][10]; char map[10][10]; int n,ans,ss,t ...

  7. HDU 4597 Play Game(记忆化搜索,深搜)

    题目 //传说中的记忆化搜索,好吧,就是用深搜//多做题吧,,这个解法是搜来的,蛮好理解的 //题目大意:给出两堆牌,只能从最上和最下取,然后两个人轮流取,都按照自己最优的策略,//问说第一个人对多的 ...

  8. HDU 3666 THE MATRIX PROBLEM (差分约束 深搜 & 广搜)

    THE MATRIX PROBLEM Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  9. hdu 1426 Sudoku Killer (dfs)

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

随机推荐

  1. strace使用详解

    (一) strace 命令   用途:打印 STREAMS 跟踪消息. 语法:strace [ mid sid level ] ... 描述:没有参数的 strace 命令将所有的驱动程序和模块中的所 ...

  2. 教程-Delphi MSComm 实时串口通讯

    Delphi  MSComm 实时串口通讯 MSComm控件具有丰富的与串口通信密切相关的属性,提供了对串口进行的多种操作,进而使串行通信变得十分简便.MSComm的控件属性较多,常用的属性如下:1) ...

  3. 使用sessionStorage得一个坑

    1.首先sessionStorage.setItem("isMybill" false) 2.使用的时候 sessionStorage.getItem('isMybill')  / ...

  4. Lua 第一个应用程序 Hello World

    lua 开发环境的搭建 现已windows系统为例,演示一下lua环境的搭建. Lua_v5.1.4 下载地址 http://code.google.com/p/luaforwindows/ 点击&q ...

  5. 统一建模语言(UML) 版本 2.0

    原文: http://www.ibm.com/developerworks/cn/rational/321_uml/ 简介 参考 UML 基础系列的其他文章和教程 UML基础: 统一建模语言简介 UM ...

  6. 向架构师进军---&gt;怎样编写软件架构文档

    假设你对项目管理.系统架构有兴趣,请加微信订阅号"softjg",增加这个PM.架构师的大家庭 问:为什么要编写软件架构文档,它的优点是什么? 答: 有文档的架构有助于不同利益相关 ...

  7. 13 引用WINAPI

            [System.Runtime.InteropServices.DllImport("user32.dll", EntryPoint = "SetWind ...

  8. C#如何检测一个字符串是不是合法的URL

    C#如何检测一个字符串是不是合法的URL using System.Text.RegularExpressions;    /// <summary>         /// 检测串值是否 ...

  9. cocos2dx lua学习笔记 &lt;一&gt; quick 3.5定义本身C++类是必然lua

    请尊重原创 转载有名源:http://blog.csdn.net/wushao126/article/details/46660375 首先去官网下载最新的quick.配置好环境.创建一个luapro ...

  10. iOS之获取当前时间日期并按固定格式显示

    写一个常用的获取当前日期,时间的代码.并且能以规定的格式显示出来 1 2 3 4 5 NSDate *currentDate = [NSDate date];//获取当前时间,日期 NSDateFor ...