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 ...
随机推荐
- firewall和iptables
防火墙有这三种方式,firewalld.iptables.ebtables,现在的centOS7使用的是firewalld. 下面是一些总结: 查看当前firewalld的状态 firewall-cm ...
- python中使用%与.format格式化文本
初学python,看来零零碎碎的格式化文本的方法,总结一下python中格式化文本的方法.使用不当的地欢迎指出谢谢. 1.首先看使用%格式化文本 常见的占位符: 常见的占位符有: %d 整数 %f 浮 ...
- noi.acNOIP模拟赛5-count
题目链接 戳我 题意简述 你有一个n+1个数的序列,都是1~n,其中只有一个有重复,求每个长度的本质不同的子序列个数.\(mod 1e9+7\). sol 说起来也很简单,设相同的数出现的位置为\(l ...
- Android Studio下“Error:Could not find com.android.tools.build:gradle:2.2.1”的解决方法
ref from: Android Studio下“Error:Could not find com.android.tools.build:gradle:2.2.1”的解决方法http://blog ...
- CH暑假欢乐赛 SRM 07 天才麻将少女KPM(DP+treap)
首先LIS有个$O(n^2)$的DP方法 $f(i,j)$表示前i个数,最后一个数<=j的LIS 如果$a_i!=0$则有 如果$a_i=0$则有 注意因为$f(i-1,j)\leq f(i-1 ...
- sql数据库设计学习---数据库设计规范化的五个要求
http://blog.csdn.net/taijianyu/article/details/5945490 一:表中应该避免可为空的列: 二:表不应该有重复的值或者列: 三: 表中记录应该有一个唯一 ...
- eclipse 支持 Robot framework 编辑环境
一.配置python 环境 1. 设置pydev库 打开Help -> Install New Software, 点击'Add',设置Name为“Pydev”,Loca ...
- BZOJ1053:反素数(数学)
题目链接 对于任意的正整数\(x\),记其约数的个数为\(g(x)\).现在定义反素数:对于\(0<i<x\),都有\(g(x)>g(i)\),那么就称x为反素数. 现在给定一个数N ...
- 【Asp.net入门4-02】使用Visual Studio调试器
- Python高手之路【四】python函数装饰器,迭代器
def outer(func): def inner(): print('hello') print('hello') print('hello') r = func() print('end') p ...