题目链接:https://cn.vjudge.net/problem/HDU-5547

具体思路:对于每一位上,我们可以从1到4挨着去试, 具体判断这一位可不可以的时候,看当前这一位上的行和列有没有冲突,以及他所在的2*2的方格中有没有矛盾的。

AC代码:

 #include <iostream>
#include <string>
#include <deque>
#include <stack>
#include<cmath>
#include <algorithm>
#include<cstring>
#include<stdio.h>
#include<map>
using namespace std;
# define ll long long
# define inf 0x3f3f3f3f
# define ll_inf 1ll<<
const int maxn = 1e6+;
char a[][];
int b[][];
int num;
struct node
{
int x;
int y;
} q[];
bool judge(int s,int t)
{
for(int i=; i<=; i++)
{
if(i==q[t].y)
continue;
if(b[q[t].x][i]==s)
return false;
}
for(int i=; i<=; i++)
{
if(i==q[t].x)
continue;
if(b[i][q[t].y]==s)
return false;
}
int t1=q[t].x,t2=q[t].y;
if(t1%==&&t2%==)
{
t1--;
t2--;
for(int i=; i<=; i++)
{
for(int j=; j<=; j++)
{
int x=t1+i;
int y=t2+j;
if(x==q[t].x&&y==q[t].y)
continue;
if(b[x][y]==s)
return false;
}
}
}
else if(t1%==&&t2%!=)
{
t1--;
for(int i=; i<=; i++)
{
for(int j=; j<=; j++)
{
int x=t1+i;
int y=t2+j;
if(x==q[t].x&&y==q[t].y)
continue;
if(b[x][y]==s)
return false;
}
}
}
else if(t1%!=&&t2%==)
{
t2--;
for(int i=; i<=; i++)
{
for(int j=; j<=; j++)
{
int x=t1+i;
int y=t2+j;
if(x==q[t].x&&y==q[t].y)
continue;
if(b[x][y]==s)
return false;
}
}
}
else if(t1%!=&&t2%!=)
{
for(int i=; i<=; i++)
{
for(int j=; j<=; j++)
{
int x=t1+i;
int y=t2+j;
if(x==q[t].x&&y==q[t].y)
continue;
if(b[x][y]==s)
return false;
}
}
}
return true;
}
void dfs(int t)
{
// cout<<t<<endl;
if(t==num+)
{
for(int i=; i<=; i++)
{
for(int j=; j<=; j++)
{
printf("%d",b[i][j]);
}
printf("\n");
}
return ;
}
for(int i=; i<=; i++)
{
if(judge(i,t))
{
// cout<<1<<endl;
b[q[t].x][q[t].y]=i;
dfs(t+);
b[q[t].x][q[t].y]=;
}
}
}
int main()
{
int T;
scanf("%d",&T);
int Case=;
while(T--)
{
num=;
for(int i=; i<=; i++)
{
scanf("%s",a[i]+);
for(int j=; j<=; j++)
{
// cout<<a[i][j];
if(a[i][j]=='*')
{
q[++num].x=i;
q[num].y=j;
b[i][j]=;
}
else
b[i][j]=a[i][j]-'';
}
}
printf("Case #%d:\n",++Case);
dfs();
}
return ;
}

E - Sudoku HDU - 5547 (搜索+暴力)的更多相关文章

  1. The 2015 China Collegiate Programming Contest H. Sudoku hdu 5547

    Sudoku Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Subm ...

  2. hdu 5887 搜索+剪枝

    Herbs Gathering Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  3. hdu 5636 搜索 BestCoder Round #74 (div.2)

    Shortest Path  Accepts: 40  Submissions: 610  Time Limit: 4000/2000 MS (Java/Others)  Memory Limit: ...

  4. UVA.129 Krypton Factor (搜索+暴力)

    UVA.129 Krypton Factor (搜索+暴力) 题意分析 搜索的策略是:优先找长串,若长串不合法,则回溯,继续找到合法串,直到找到所求合法串的编号,输出即可. 注意的地方就是合法串的判断 ...

  5. Square HDU 1518 搜索

    Square HDU 1518 搜索 题意 原题链接 给你一定若干个木棒,让你使用它们组成一个四边形,要求这些木棒必须全部使用. 解题思路 木棒有多种组合方式,使用搜索来进行寻找,这里需要进行优化,不 ...

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

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

  7. HDU 5547 Sudoku (暴力)

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

  8. HDU 5547 Sudoku(DFS)

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

  9. HDU 5547 暴力

    Sudoku Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Subm ...

随机推荐

  1. dividend = Integer.parseInt(args[0])参数问题

    先来一段代码: package yichang; public class MyExceptionTest { public static void main(String[] args) { int ...

  2. Qt 5.9.1 连 MYSQL 5.7数据库

    Qt程序报错: QSqlDatabase: QMYSQL driver not loaded QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQ ...

  3. EF 使用 oracle

    EF 使用 oracle https://www.oracle.com/technetwork/topics/dotnet/downloads/index.html C:\Program Files ...

  4. Android中的Surface, SurfaceHolder, SurfaceHolder.Callback, SurfaceView

    传入一个surface,然后让openGL在surface上画图 window->view hierachy(DecorView是tree的root)->ViewRoot->Surf ...

  5. Tcp协议三次握手四次挥手

    一.什么是TCP TCP(Transmission Control Protocol 传输控制协议)是一种面向连接(连接导向)的.可靠的. 基于IP的传输层协议.TCP在IP报文的协议号是6. 二.什 ...

  6. ALC662 在Mac中的安装

    最近在装黑苹果,一切还算顺利(整了两周),就是ICH7的ALC662一直无法驱动成功.经过两天的爬文,终于成功了.以下是我的一点经验. 我装的是最新的10.9.2,显卡驱动是自带的(我的显卡为GT62 ...

  7. dev代码拷贝中文乱码的解决方案

    .c / .cpp文件用记事本打开,再拷贝

  8. SenseTime Ace Coder Challenge 暨 商汤在线编程挑战赛 D. 白色相簿

    从某一点开始,以层次遍历的方式建树若三点a.b.c互相连接,首先必先经过其中一点a,然后a可以拓展b.c两点,b.c两点的高度是相同的,若b(c)拓展时找到高度与之相同的点,则存在三点互相连接 //等 ...

  9. Python 爬虫入门(三)—— 寻找合适的爬取策略

    写爬虫之前,首先要明确爬取的数据.然后,思考从哪些地方可以获取这些数据.下面以一个实际案例来说明,怎么寻找一个好的爬虫策略.(代码仅供学习交流,切勿用作商业或其他有害行为) 1).方式一:直接爬取网站 ...

  10. php static 变量用法

    有时候我们可能需要重复调用一个函数,里面有些变量不需要重复初始化.初始化成本比较高的,我们可以使用 static 关键字修饰,在该变量没有初始化的时候才进行初始化,初始化过的变量就不再初始化.如: f ...