(hdu)5547 Sudoku (4*4方格的 数独 深搜)
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方格的 数独 深搜)的更多相关文章
- HDU - 5547 Sudoku(数独搜索)
Description Yi Sima was one of the best counselors of Cao Cao. He likes to play a funny game himself ...
- HDU 5547 Sudoku(DFS)
题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=5547 题目: Sudoku Time Limit: 3000/1000 MS (Java/Others ...
- HDU 1426 Sudoku Killer(dfs 解数独)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1426 Sudoku Killer Time Limit: 2000/1000 MS (Java/Oth ...
- HDU 5547 Sudoku (暴力)
题意:数独. 析:由于只是4*4,完全可以暴力,要注意一下一些条件,比如2*2的小方格也得是1234 代码如下: #pragma comment(linker, "/STACK:102400 ...
- [NOIP2009]靶形数独 深搜+枝杈优化
这道题,又是一位玄学搜索...... 我是用的蜗牛序搜的(顾名思义,@,这么搜),我正着搜80然后一反转比原来快了几十倍........一下AC....... 我的思路是这样的话我们可以从内到外或者从 ...
- hdu 1045 要求全部逐一搜索完的深搜
#include<stdio.h> #include<string.h> int visit[10][10]; char map[10][10]; int n,ans,ss,t ...
- HDU 4597 Play Game(记忆化搜索,深搜)
题目 //传说中的记忆化搜索,好吧,就是用深搜//多做题吧,,这个解法是搜来的,蛮好理解的 //题目大意:给出两堆牌,只能从最上和最下取,然后两个人轮流取,都按照自己最优的策略,//问说第一个人对多的 ...
- HDU 3666 THE MATRIX PROBLEM (差分约束 深搜 & 广搜)
THE MATRIX PROBLEM Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- hdu 1426 Sudoku Killer (dfs)
Sudoku Killer Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
随机推荐
- 【Java基础】Java中的持久属性集Properties
Properties 类的介绍 Properties 类表示了一个持久的属性集.Properties 可保存在流中或从流中加载.属性列表中每个键及其对应值都是一个字符串.一个属性列表可包含另一个属性列 ...
- 委托demo
delegate bool Filter(string s); class test { static void Main() { Filter f=new Filter(A); Display(ne ...
- oc学习之路----代理模式
今天刚学完oc的代理模式,觉得有点新奇,第一次接触,原理 A完成一件事,但是自己不能完成,于是他找个代理人B 替他完成这个事情,他们之间便有个协议 (protocol),B继承该协议来完成A代理给他的 ...
- 写一些有关android的东西吧,那时候玩android时候的一些笔记
写一些有关android的东西吧,那时候玩android时候的一些笔记
- python版的短信轰炸机smsbomb----------下篇(get)
在上一篇介绍的是post方式发送数据,可是有点站点是get方式发送数据,比如:http://www.oupeng.com/download,事实上方法差点儿相同. import httplib,url ...
- 杂谈:你选择coco 还是unity3d?
当一个人喜欢的时候,那么这样的兴趣是非常难改变的.你是否会改变自己想法?眼下而言,如今adobe 对flash开发处于维护的状态.为什么?是由于前期错误政策流失非常多人才,这一点也非常难避免.当今年湖 ...
- Android - TextView Ellipsize属性
Android - TextView Ellipsize属性 本文地址: http://blog.csdn.net/caroline_wendy android:ellipsize属性: If set ...
- Unityclient通信測试问题处理(二)
Unityclient通信測试问题处理(二) 在client的通信測试过程中.场景载入的问题给自己带来了不小的麻烦.由于消息的解析方法在单独的监听线程中调用,这也就意味着无法在消息的解析方法中调用Un ...
- 算法 - 求和为n的连续正整数序列(C++)
//************************************************************************************************** ...
- iOS 中UI控件的各种对齐方式总结
1.textAligment : 文字的水平方向的对齐方式 取值 NSTextAlignmentLeft = 0, // 左对齐 NSTextAlignmentCenter = ...