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. HDU4417 - Super Mario(主席树)

    题目大意 给定一个数列,每次要求你查询区间[L,R]内不超过K的数的数量 题解 和静态的区间第K大差不多,这题是<=K,先建立好n颗主席树,然后用第R颗主席树区间[1,K]内数的数量减去第L-1 ...

  2. WeUI首页、文档和下载 - 专为微信设计的 UI 库 - 开源中国社区

    Download Bitnami Review Board Stack click here WeUI首页.文档和下载 - 专为微信设计的 UI 库 - 开源中国社区

  3. BOM 和 JavaScript 中的 trim

    今天遇到一个 IE7 下 JSON.parse 失败的问题.经过排查发现:服务端某个配置文件编码是 UTF-8 + BOM,输出的字符串最开始包含了 BOM 字符,不是合法的 JSON. IE7 不支 ...

  4. Powerdesigner设置name与code不同时变化

    Tools-General Options-Dialog Name to Code mirroring去掉对勾

  5. [三]JFreeChart实践二

    功能: 1.设置带色彩的柱状图 2.可以设置多组数据的展示 3.可以设置图标的背景色 4.可以设置柱与柱之间的距离 5.可以设置柱子上边是否显示具体的数值

  6. ADODB.Connection 错误 '800a0e7a' 未找到提供程序 该程序可能未正确安装

    今天调程序的时候发现的,错误提示如下: ADODB.Connection 错误 '800a0e7a' 未找到提供程序.该程序可能未正确安装. /conn.asp,行 6 因为系统是64位的win7或w ...

  7. C++下字符串转换

    引用自:http://blog.sina.com.cn/s/blog_a98e39a20101ari9.html 把最近用到的各种unicode下类型转换总结了一下,今后遇到其他的再补充: 1.str ...

  8. android ORMlite的应用

    ORMLite -轻量级的对象关系映射(ORM) 如果你需要在android中使用ORMLite 你需要进入官方网站http://ormlite.com/ 中下载 下载了这两个包以后,你还需要在对应的 ...

  9. Oracle--SQL Developer创建连接及使用

    安装好Oracle之后,有几种方式可以来管理Oracle中的数据库,首先就是登陆网页版的界面:https://localhost:1158/em,这种方式管理的东西太多,使用起来有点不方便,第二种方式 ...

  10. redis远程连接超时

     今天在用jedis连接远程的redis时,抛出连接超时异常:connect timed out. 详细信息例如以下: Exception in thread "main" r ...