E - Sudoku HDU - 5547 (搜索+暴力)
题目链接: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 (搜索+暴力)的更多相关文章
- 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 ...
- hdu 5887 搜索+剪枝
Herbs Gathering Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- hdu 5636 搜索 BestCoder Round #74 (div.2)
Shortest Path Accepts: 40 Submissions: 610 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: ...
- UVA.129 Krypton Factor (搜索+暴力)
UVA.129 Krypton Factor (搜索+暴力) 题意分析 搜索的策略是:优先找长串,若长串不合法,则回溯,继续找到合法串,直到找到所求合法串的编号,输出即可. 注意的地方就是合法串的判断 ...
- Square HDU 1518 搜索
Square HDU 1518 搜索 题意 原题链接 给你一定若干个木棒,让你使用它们组成一个四边形,要求这些木棒必须全部使用. 解题思路 木棒有多种组合方式,使用搜索来进行寻找,这里需要进行优化,不 ...
- 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 (暴力)
题意:数独. 析:由于只是4*4,完全可以暴力,要注意一下一些条件,比如2*2的小方格也得是1234 代码如下: #pragma comment(linker, "/STACK:102400 ...
- HDU 5547 Sudoku(DFS)
题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=5547 题目: Sudoku Time Limit: 3000/1000 MS (Java/Others ...
- HDU 5547 暴力
Sudoku Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total Subm ...
随机推荐
- vue 组件 模板中根数据绑定需要指明路径并通信父
<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>T ...
- 链表java实现
链表是用指针将多个节点联系在一起,通过头节点和尾节点还有节点数量,可以对链表进行一系列的操作.是线性表的链式存储实现. 1.链表是多个不连续的地址组成在一起根据指针链接在一起的,由多个节点组成,每个节 ...
- 【大数据】MapTask工作机制
1.MapTask工作机制 整个map阶段流程大体如上图所示.简单概述:input File通过getSplits被逻辑切分为多个split文件,通通过RecordReader(默认使用lineRec ...
- BZOJ5324 JXOI2018守卫(区间dp)
对于每个区间[l,r],显然右端点r是必须放置守卫的.考虑其不能监视到的点,构成一段段区间.一个非常显然但我就是想不到的性质是,对于这样的某个区间[x,y],在(y+1,r)内的点都是不能监视到这个区 ...
- Nagios通过企业微信报警
主要分两部分进行: 注册企业微信,自建应用,获取与发送消息相关的信息: 编写调用微信API脚本(bash),配置Nagios微信报警: 一.企业微信 1.注册企业微信:https://work.wei ...
- Docker Machine 和 Docker Engine 的区别
Docker Engine 当人们提到 Docker,一般而言,大家说的是 Docker Engine,如下图: 它是一个 client-server application. Docker Eng ...
- 【bzoj3730】 震波
http://www.lydsy.com/JudgeOnline/problem.php?id=3730 (题目链接) 题意 给出一棵树,每个节点又一个权值.两个操作,询问距离节点${x}$不超过${ ...
- UVA.10325 The Lottery (组合数学 容斥原理 二进制枚举)
UVA.10325 The Lottery (组合数学 容斥原理) 题意分析 首先给出一个数n,然后给出m个数字(m<=15),在[1-n]之间,依次删除给出m个数字的倍数,求最后在[1-n]之 ...
- 解题:CF983B pyramid
题面 题目都告诉我们是“金字塔”了,不妨分析分析$f$的性质 $f(a_1,a_2)=f(a_1$ $xor$ $a_2)=a1$ $xor$ $a_2$ $f(a_1,a_2,a_3)=f(a_1$ ...
- 支付宝当面付功能demo运行解读
下载java版本的sdk的demo: 然后拷入idea中: 准备工作: (1)验签工具下载:蚂蚁金服上面下载: https://openclub.alipay.com/read.php?tid=955 ...