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 ...
随机推荐
- spring的jar包以及相关的API文档的下载方式
转自:http://blog.csdn.net/yuexianchang/article/details/53583327 侵删 感谢原创 首先是进入官网:https://spring.io/ 如图所 ...
- 数据库事物 jdbc事物 spring事物 隔离级别:脏幻不可重复读
1.数据库事物: 事物的概念 a给b打100块钱的例子 2.jdbc事物: 通过下面代码实现 private Connection conn = null; private PreparedState ...
- mysql用mysqldump数据库备份和恢复
备份: 用mysqldump命令把数据库被分成sql文件:(注意是在cmd里,不用进入数据库,输入之后会提示输入密码) mysqldump -hlocalhost -uroot -p testdb & ...
- 【APIO 2018】铁人两项(圆方树)
题目链接 题意大概是,求有多少三元组$(s,c,f)(s \neq c, c \neq f, s \neq f)$,满足从$s$到$f$有一条简单路径经过$c$. 得到结论: 点双中任意互不相同的三个 ...
- 【Cf #290 C】Fox And Dinner(最大流)
如果要相邻两个数(a[i] >= 2)相加为质数,显然它们的奇偶性不同,也就是说一个圆桌(环)必须是偶环. 也就是答案的若干个环组成了一张二分图,其中以奇偶分色. 考虑每个点的度数一定为2,用最 ...
- Linux及安全实践四——ELF文件格式分析
Linux及安全实践四——ELF文件格式分析 一.ELF文件格式概述 1. ELF:是一种对象文件的格式,用于定义不同类型的对象文件中都放了什么东西.以及都以什么样的格式去放这些东西. 二.分析一个E ...
- nginx 配置 phpmyadmin
server { listen 8092; server_name *.xxx.com; root /home/users/cuijian04/odp302/app/phpmyadmin; set $ ...
- CSS的overflow属性介绍
overflow 属性规定如何处理如何处理不符合元素框的内容.用法如下:Object.style.overflow=visible|hidden|scroll|auto. 参数介绍: visible: ...
- python定义函数以及参数检查
(转自廖雪峰网站) 函数定义 在Python中,定义一个函数要使用def语句,依次写出函数名.括号.括号中的参数和冒号:,然后,在缩进块中编写函数体,函数的返回值用return语句返回. 我们以自定义 ...
- expect详解及自动登录脚本的实现
expect可以让一些交互的任务自动完成,我们可以将一些交互过程写入脚本,ssh登录就是一个简单的实现,下面将介绍expect的用法. 1 安装 yum install -y expect 2 语法介 ...