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. vi / vim 删除以及其它命令

    删除一行:dd 删除一个单词/光标之后的单词剩余部分:dw 删除当前字符:x 光标之后的该行部分:d$ 文本删除 dd 删除一行 d$ 删除以当前字符开始的一行字符 ndd 删除以当前行开始的n行 d ...

  2. Oracle数据库字符串连接方法

    转至:http://database.51cto.com/art/201011/232267.htm 和其他数据库系统类似,Oracle字符串连接使用“||”进行字符串拼接,其使用方式和MSSQLSe ...

  3. mysql-no-install 手动安装

    D:\mysql-5.5.28-win32 1.下载mysql-5.5.15-win32.zip,解压到本地D:\mysql. 2.将my-small.ini另存为my.ini .(根据情况可以选择别 ...

  4. 前端javascript规范文档 (http://www.xuanfengge.com/category/web)

    说明:本文档为前端JS规范 一.规范目的 为提高团队协作效率,便于前端后期优化维护,输出高质量的文档. 二.基本准则 符合web标准,结构表现行为分离,兼容性优良.页面性能方面,代码要求简洁明了有序, ...

  5. 在C#中我们能调用一个类的私有方法吗

    博客搬到了fresky.github.io - Dawei XU,请各位看官挪步.最新的一篇是:在C#中我们能调用一个类的私有方法吗.

  6. 删除mysql服务

    当我们卸载完MySQL后重新装MySQL提示 The service already exists! 是因为服务名称还残留在系统里 打开cmd 输入下面 sc delete mysql 这个mysql ...

  7. WPF WebBrowser

      XAML <Window x:Class="WpfApplication5.Window1"     xmlns="http://schemas.microso ...

  8. java20 创建服务器:ServerSocket

    创建服务器:ServerSocket import java.io.BufferedReader; import java.io.IOException; import java.io.InputSt ...

  9. hdu2565java

    放大的X Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submissio ...

  10. css :after和:before

    :before是css中的一种伪元素,可用于在某个元素之前插入某些内容.:after是css中的一种伪元素,可用于在某个元素之后插入某些内容. 举例: 1.结合border写个对话框的样式. < ...