hdu第4场j.Let Sudoku Rotate
Problem J. Let Sudoku Rotate Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others)
Total Submission(s): Accepted Submission(s): Problem Description
Sudoku is a logic-based, combinatorial number-placement puzzle, which is popular around the world.
In this problem, let us focus on puzzles with × grids, which consist of × 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 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? Input
The first line of the input contains an integer T (≤T≤) denoting the number of test cases.
Each test case consists of exactly lines with characters each, describing a broken sudoku. Output
For each test case, print a non-negative integer indicating the minimum possible number of operations. Sample Input 681D5A0C9FDBB2F7
0A734B62E167D9E5
5C9B73EF3C208410
F24ED18948A5CA63
39FAED5616400B74
D120C4B7CA3DEF38
7EC829A085BE6D51
B56438F129F79C2A
5C7FBC4E3D08719F
AE8B1673BF42A58D
60D3AF25619C30BE
294190D8EA57264C
C7D1B35606835EAB
AF52A1E019BE4306
8B36DC78D425F7C9
E409492FC7FA18D2 Sample Output Hint The original sudoku is same as the example in the statement.

搜索。 转3次。跟行列又重复就返回;
#include<iostream>
#include<stdio.h>
#include<cmath>
#include<algorithm>
#include<string.h>
using namespace std;
#define ll long long
int ans;
int a[][];
int tmp[][]={};
void rotat(int x,int y)
{
for(int i=;i<=;i++)
for(int j=;j<=;j++)
tmp[j][-i+]=a[(x-)*+i][(y-)*+j];
for(int i=;i<=;i++)
for(int j=;j<=;j++)
a[(x-)*+i][(y-)*+j]=tmp[i][j];
}
bool check(int x,int y)
{
int book[];
for(int i=x*-;i<=x*;i++)
{
memset(book,,sizeof book);
for(int j=;j<=y*;j++)
{
if(!book[a[i][j]])
book[a[i][j]]=;
else
return ;
}
}
for(int j=y*-;j<=y*;j++)
{
memset(book,,sizeof book);
for(int i=;i<=x*;i++)
{
if(!book[a[i][j]])
book[a[i][j]]=;
else
return ;
}
}
return ;
} void bfs(int x,int y,int sum)
{
if(x==)
{
if(ans>sum)
ans=sum;
return;
}
if(sum>ans)
{
return;
}
for(int i=;i<;i++)
{
if(i) rotat(x,y);
if(check(x,y))
{
if(y+<=)
bfs(x,y+,sum+i);
else
bfs(x+,,sum+i);
}
}
rotat(x,y);
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
ans=*;
char str[];
for(int i=;i<=;i++)
{
scanf("%s",str+);
for(int j=;j<=;j++)
{
if(str[j]>'')
a[i][j]=str[j]-'A'+;
else a[i][j]=str[j]-'';
} }
bfs(,,);
cout<<ans<<endl; } return ;
}
hdu第4场j.Let Sudoku Rotate的更多相关文章
- 2018 Multi-University Training Contest 4 Problem J. Let Sudoku Rotate 【DFS+剪枝+矩阵旋转】
任意门:http://acm.hdu.edu.cn/showproblem.php?pid=6341 Problem J. Let Sudoku Rotate Time Limit: 2000/100 ...
- HDU - 6341 多校4 Let Sudoku Rotate(状压dfs)
Problem J. Let Sudoku Rotate Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K ...
- hdu6341 Problem J. Let Sudoku Rotate (dfs)
题目传送门 题意: 给你16个16宫格的数独,里面是0~F,你可以逆时针旋转里面的每个16宫格 问你它是从标准数独逆时针旋转多少次得到? 思路: 可以知道每个16宫已经是标准的了,接下来只要考虑每行. ...
- HDU-6341 Problem J. Let Sudoku Rotate(dfs 剪枝)
题目:有一个4*4*4*4的数独,每一横每一竖每一个小方块中都无重复的字母,即都为0-9,A-F..有一个已经填好的数独,若干个4*4的方块被逆时针拧转了若干次,问拧转回来至少需要多少次. 分析:很明 ...
- 牛客多校第3场 J 思维+树状数组+二分
牛客多校第3场 J 思维+树状数组+二分 传送门:https://ac.nowcoder.com/acm/contest/883/J 题意: 给你q个询问,和一个队列容量f 询问有两种操作: 0.访问 ...
- HDU暑假多校第四场J-Let Sudoku Rotate
一.题意 Sudoku is a logic-based, combinatorial number-placement puzzle, which is popular around the wor ...
- 2014多校第一场J题 || HDU 4870 Rating(DP || 高斯消元)
题目链接 题意 :小女孩注册了两个比赛的帐号,初始分值都为0,每做一次比赛如果排名在前两百名,rating涨50,否则降100,告诉你她每次比赛在前两百名的概率p,如果她每次做题都用两个账号中分数低的 ...
- 2014 HDU多校弟六场J题 【模拟斗地主】
这是一道5Y的题目 有坑的地方我已在代码中注释好了 QAQ Ps:模拟题还是练的太少了,速度不够快诶 //#pragma comment(linker, "/STACK:16777216&q ...
- 2014 HDU多校弟五场J题 【矩阵乘积】
题意很简单,就是两个大矩阵相乘,然后求乘积. 用 Strassen算法 的话,当N的规模达到100左右就会StackOverFlow了 况且输入的数据范围可达到800,如果变量还不用全局变量的话连内存 ...
随机推荐
- CCF CSP 201503-1 图像旋转 (降维)
题目链接:http://118.190.20.162/view.page?gpid=T27 问题描述 试题编号: 201503-1 试题名称: 图像旋转 时间限制: 5.0s 内存限制: 256.0M ...
- [dart学习]第二篇:dart变量介绍 (一)
前言 本文的所有内容均是官方文档的简单翻译和理解,需要查看原文,请登录 https://www.dartlang.org/guides/language/language-tour 阅读, 让我们 ...
- 基于ROS完成寻迹运动
安装opencv功能包: $ sudo apt-get install ros-indigo-version-opencv libopencv-dev python-opencv 检测指示线: #! ...
- JS中if判断 非空即为真 非0即为真
1.字符串参与判断时:非空即为真判断字符串为空的方法if(str!=null && str!=undefined && str !='')可简写为if(!str){ ...
- 软件包管理(rpm,yum)
软件包管理相关软件: 软件包管理器的核心功能: .制作软件包 .安装,卸载,升级,查询,效验 Redhat ,SUSE : RPM Debian :dpt 依赖关系; 前端工具;yum ,apt-ge ...
- C#线程同步(3)- 互斥量 Mutex
文章原始出处 http://xxinside.blogbus.com/logs/47162540.html 预备知识:C#线程同步(1)- 临界区&Lock,C#线程同步(2)- 临界区&am ...
- mysql基操
创建数据表: create table tt1( id int, name varchar(20), age int,sex boolean ); insert into tt1 values(1,& ...
- 单元测试系列之九:Sonar 常用代码规则整理(一)
更多原创测试技术文章同步更新到微信公众号 :三国测,敬请扫码关注个人的微信号,感谢! 摘要:公司部署了一套sonar,经过一段时间运行,发现有一些问题出现频率很高,因此有必要将这些问题进行整理总结和分 ...
- IIC为什么要配置为开漏输出呢?
开漏输出只能输出低电平,类似于三极管的集电极,要输出高电平需要上拉电阻才能输出 当集电极接上拉电阻后,(1)基极为高电平,三极管导通,集电极的电位就会被拉低: (2)基极为低电平,三极管不导通,集电极 ...
- RFS--RequestLibrary
一.requestlibrary关键字1.1create session:创建一个session回话.Create Session: 创建一个session,连接某个服务器.Create Ntlm S ...