hdu-6341-搜索
Problem J. Let Sudoku Rotate
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 530 Accepted Submission(s): 146
In this problem, let us focus on puzzles with 16×16 grids, which consist of 4×4 regions. The objective is to fill the whole grid with hexadecimal digits, i.e. 0123456789ABCDEF, so that each column, each row, and each region contains all hexadecimal digits. The figure below shows a solved sudoku.

Yesterday, Kazari solved a sudoku and left it on the desk. However, Minato played a joke with her - he performed the following operation several times.
* Choose a region and rotate it by 90 degrees counterclockwise.
She burst into tears as soon as she found the sudoku was broken because of rotations.
Could you let her know how many operations her brother performed at least?
Each test case consists of exactly 16 lines with 16 characters each, describing a broken sudoku.
681D5A0C9FDBB2F7
0A734B62E167D9E5
5C9B73EF3C208410
F24ED18948A5CA63
39FAED5616400B74
D120C4B7CA3DEF38
7EC829A085BE6D51
B56438F129F79C2A
5C7FBC4E3D08719F
AE8B1673BF42A58D
60D3AF25619C30BE
294190D8EA57264C
C7D1B35606835EAB
AF52A1E019BE4306
8B36DC78D425F7C9
E409492FC7FA18D2
The original sudoku is same as the example in the statement.
当时总感觉复杂度会炸,后来看题解才悟到其实由于数独的限制性较强,可以减去很大一部分无用解,然后就是普通的深搜了,
关键在于如何处理这个棋盘,我是一个一个区域处理的,枚举每个区域的旋转次数,如果和之前的不冲突就往下一个区域dfs,注意的是
函数返回的时候要将rotate过得区域再ratate回去。
#include<bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
int ans,h[],c[],e[][],g[][];
bool vis[];
void rotate(int a,int b){
int i1,i2,j1,j2;
for(i1=*a-,j2=*b-;i1<=*a;++i1,j2++){
for(j1=*b-,i2=*a;j1<=*b;++j1,i2--){
g[i1][j1]=e[i2][j2];
}
}
for(int i=*a-;i<=*a;++i){
for(int j=*b-;j<=*b;++j){
e[i][j]=g[i][j];
}
}
}
bool ok(int x,int y){
for(int i=*x-;i<=*x;++i){
memset(vis,,sizeof(vis));
for(int j=;j<=y*;++j){
if(vis[e[i][j]]) return ;
vis[e[i][j]]=;
}
}
for(int j=*y-;j<=*y;++j){
memset(vis,,sizeof(vis));
for(int i=;i<=*x;++i){
if(vis[e[i][j]]) return ;
vis[e[i][j]]=;
}
}
return ;
}
void dfs(int x,int y,int tmp){
if(x>){
if(tmp<ans) ans=tmp;
return;
}
if(tmp>=ans) return;
for(int i=;i<;++i){
if(i) rotate(x,y);
if(ok(x,y)){
if(y==) dfs(x+,,tmp+i);
else dfs(x,y+,tmp+i);
}
}
rotate(x,y);//再转一次相当于归回原位
}
int main(){
int t,n,m,i,j,k;
char ch;
cin>>t;
while(t--){
for(i=;i<=;++i){
for(j=;j<=;++j){
cin>>ch;
e[i][j]=isdigit(ch)?ch-'':ch-'A'+;
}
}
ans=inf;
dfs(,,);
cout<<ans<<endl;
}
return ;
}
hdu-6341-搜索的更多相关文章
- 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: ...
- Square HDU 1518 搜索
Square HDU 1518 搜索 题意 原题链接 给你一定若干个木棒,让你使用它们组成一个四边形,要求这些木棒必须全部使用. 解题思路 木棒有多种组合方式,使用搜索来进行寻找,这里需要进行优化,不 ...
- hdu 4848 搜索+剪枝 2014西安邀请赛
http://acm.hdu.edu.cn/showproblem.php?pid=4848 比赛的时候我甚至没看这道题,事实上不难.... 可是说实话,如今对题意还是理解不太好...... 犯的错误 ...
- poj 1198 hdu 1401 搜索+剪枝 Solitaire
写到一半才发现能够用双向搜索4层来写,但已经不愿意改了,干脆暴搜+剪枝水过去算了. 想到一个非常水的剪枝,h函数为 当前点到终点4个点的最短距离加起来除以2.由于最多一步走2格,然后在HDU上T了, ...
- hdu 1495 (搜索) 非常可乐
http://acm.hdu.edu.cn/showproblem.php?pid=1495 搜索模拟出每此倒得情况就好,详情见代码\ (好困啊!!!!1) #include<cstdio> ...
- hdu 4665 搜索
思路:直接搜索 #include<iostream> #include<cstdio> #include<algorithm> #include<cstrin ...
- HDU(搜索专题) 1000 N皇后问题(深度优先搜索DFS)解题报告
前几天一直在忙一些事情,所以一直没来得及开始这个搜索专题的训练,今天做了下这个专题的第一题,皇后问题在我没有开始接受Axie的算法低强度训练前,就早有耳闻了,但一直不知道是什么类型的题目,今天一看,原 ...
- hdu 4620 搜索
好苦逼,为啥数组开小了,不会runtime error,还得我WA了几个小时,我泪流满面. 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4620 #i ...
- hdu&&poj搜索题题号
搜索 hdu1067 哈希 hdu1401 双向搜索 hdu1430 哈希 hdu1667 跌搜+启发式函数 hdu1685 启发式搜索 hdu1813 启发式搜索 hdu1885 状态压缩搜索 hd ...
随机推荐
- (zhuan) LSTM Neural Network for Time Series Prediction
LSTM Neural Network for Time Series Prediction Wed 21st Dec 2016 Neural Networks these days are the ...
- JMeter 生成CSV文件中文变乱码的问题
在通过BeanShell 生成CSV文件时,写入的中文字符默认情况会变成乱码. //默认情况生成的文件是asii编码.fileName = “c:\test.csv";fos = new F ...
- _itemmod_extra_equipments
双甲 可以控制获得属性的倍率,及是否可以取回物 `stat_muil`属性倍率(item_template中stat) `enchant_muil`附魔效果中的属性倍率(一些附魔会提升属性,可在些配置 ...
- 蚂蚁金服“定损宝”现身AI顶级会议NeurIPS
小蚂蚁说: 长期以来,车险定损(通过现场拍摄定损照片确定车辆损失,以作为保险公司理赔的依据)是车险理赔中最为重要的操作环节.以往传统保险公司的车险处理流程,一般为报案.现场查勘.提交理赔材料.审核.最 ...
- 51nod 1185 || 51nod 1072 威佐夫博弈
贴个模板:平常的跟高精度java的: int: #pragma comment(linker, "/STACK:1024000000,1024000000") #include&l ...
- django 应用中获取访问者ip地址
通常访问者的IP就在其中,所以我们可以用下列方法获取用户的真实IP: #X-Forwarded-For:简称XFF头,它代表客户端,也就是HTTP的请求端真实的IP,只有在通过了HTTP 代理或者负载 ...
- 3.1 vue组件的使用
1. 组件 组件: 组件是一个局部功能界面,它包含了所有要实现这个功能界面的相关资源,如css.html等. 组件化编程: vue文件包含3个部分 <template> <div&g ...
- Java SE 枚举的基本用法
出于对自己基础的稳打,期末考试后依旧对SE部分进行复习 枚举的基本用法 public enum Season { SPRING,SUMMER,AUTUMN,WINTER } public class ...
- 设计模式(三)Singleton Pattern单例设计模式
1.饿汉式 public class SingletonDemo { private static SingletonDemo s=new SingletonDemo(); private Singl ...
- git push 使用
git push命令用于将本地分支的更新,推送到远程主机.它的格式与git pull命令相仿. $ git push <远程主机名> <本地分支名>:<远程分支名> ...