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 小组件input keyup.enter绑定
<div id="todo-list-example"> <input v-model="newTodoText" v-on:keyup.en ...
- day02--Python基础二(基础数据类型)
一.数据与数据类型 1 什么是数据? x=10,10是我们要存储的数据 2 为何数据要分不同的类型 数据是用来表示状态的,不同的状态就应该用不同的类型的数据去表示 3 数据类型 数字(int) 字符串 ...
- 【设计模式】—— 原型模式Prototype
前言:[模式总览]——————————by xingoo 模式意图 由于有些时候,需要在运行时指定对象时哪个类的实例,此时用工厂模式就有些力不从心了.通过原型模式就可以通过拷贝函数clone一个原有的 ...
- [C/C++] 输入函数getline(cin,str) 与cin.getline(str,int)区别
cin.getline()函数是处理数组字符串的,其原型为cin.getline(char * , int),第一个参数为一个char指针,第二个参数为数组字符串长度. getline(cin,str ...
- Keil MDK中单个c文件生成LIB文件
看大多数说的都是简单地将整个工程转换成.LIB,在Project->Options for Target->Output下,选择Create Library,就可以了. 不过这样生成的li ...
- 项目开发中git常用命令、git工作流、git分支模型
#新建代码库git init # 在当前目录新建一个Git代码库git init [project-name] # 新建一个目录,将其初始化为Git代码库git clone [url] # 下载一个项 ...
- web中的懒加载
在Web应用程序中,系统的瓶颈常在于系统的响应速度.如果系统响应速度过慢,用户就会出现埋怨情绪,系统的价值也因此会大打折扣.因此,提高系统响应速度,是非常重要的. Web应用程序做的最多就是和后台数据 ...
- 约瑟夫环问题算法(M)
http://blog.csdn.net/zhuimengzh/article/details/6727221 用户输入M,N值,从1至N开始顺序循环数数,每数到M输出该数值,直至全部输出.写出C程序 ...
- Hadoop基础原理
Hadoop基础原理 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 业内有这么一句话说:云计算可能改变了整个传统IT产业的基础架构,而大数据处理,尤其像Hadoop组件这样的技术出 ...
- [Vue warn]: You are using the runtime-only build of Vue where the template compiler is not available. Either pre-compile the templates into render functions, or use the compiler-included build.
转载自:https://segmentfault.com/a/1190000006435886 解决办法:添加package.config.js配置文件中,添加本文章的红色部分代码 import vu ...