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的更多相关文章

  1. 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 ...

  2. HDU - 6341 多校4 Let Sudoku Rotate(状压dfs)

    Problem J. Let Sudoku Rotate Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K ...

  3. hdu6341 Problem J. Let Sudoku Rotate (dfs)

    题目传送门 题意: 给你16个16宫格的数独,里面是0~F,你可以逆时针旋转里面的每个16宫格 问你它是从标准数独逆时针旋转多少次得到? 思路: 可以知道每个16宫已经是标准的了,接下来只要考虑每行. ...

  4. HDU-6341 Problem J. Let Sudoku Rotate(dfs 剪枝)

    题目:有一个4*4*4*4的数独,每一横每一竖每一个小方块中都无重复的字母,即都为0-9,A-F..有一个已经填好的数独,若干个4*4的方块被逆时针拧转了若干次,问拧转回来至少需要多少次. 分析:很明 ...

  5. 牛客多校第3场 J 思维+树状数组+二分

    牛客多校第3场 J 思维+树状数组+二分 传送门:https://ac.nowcoder.com/acm/contest/883/J 题意: 给你q个询问,和一个队列容量f 询问有两种操作: 0.访问 ...

  6. HDU暑假多校第四场J-Let Sudoku Rotate

    一.题意 Sudoku is a logic-based, combinatorial number-placement puzzle, which is popular around the wor ...

  7. 2014多校第一场J题 || HDU 4870 Rating(DP || 高斯消元)

    题目链接 题意 :小女孩注册了两个比赛的帐号,初始分值都为0,每做一次比赛如果排名在前两百名,rating涨50,否则降100,告诉你她每次比赛在前两百名的概率p,如果她每次做题都用两个账号中分数低的 ...

  8. 2014 HDU多校弟六场J题 【模拟斗地主】

    这是一道5Y的题目 有坑的地方我已在代码中注释好了 QAQ Ps:模拟题还是练的太少了,速度不够快诶 //#pragma comment(linker, "/STACK:16777216&q ...

  9. 2014 HDU多校弟五场J题 【矩阵乘积】

    题意很简单,就是两个大矩阵相乘,然后求乘积. 用 Strassen算法 的话,当N的规模达到100左右就会StackOverFlow了 况且输入的数据范围可达到800,如果变量还不用全局变量的话连内存 ...

随机推荐

  1. shell里连接数据库,将结果输出到变量

    result=$(sqlplus -s 'ccc/ccc@21.96.34.34:1521'<<EOF ..... EOF )

  2. java面试经常问到的计算机网络问题

    GET 和 POST 的区别 GET请注意,查询字符串(名称/值对)是在 GET 请求的 URL 中发送的:/test/demo_form.asp?name1=value1&name2=val ...

  3. zigbee端口的理解

    在一个终端上,可以有多个端点endpoint,这个概念是很重要的. 一个节点可以有多个端点,0号endpoint是Zigbee device object(ZDO)用的一个端点,255号是用作广播.我 ...

  4. Max Sum Plus Plus HDU - 1024

    Max Sum Plus Plus     HDU - 1024 Now I think you have got an AC in Ignatius.L's "Max Sum" ...

  5. phpstudy-5.6.27-nts 安装redis扩展

    redis扩展安装流程 第一步: 首先直接查看一下phpinfo()的信息 找到下面两条信息 Architecture x86 PHP Extension Build API20131226,NTS, ...

  6. IDEA中Git的更新、提交、还原方法

    第一步:在提交项目之前必须先对项目进行更新,此项特别重要,如果不进行更新,别人有项目提交到服务器上,那么你的项目将会提交不上去,使用git解决冲突会比较麻烦,即使你解决了冲突,但是有时候不注意会冲掉别 ...

  7. mysqldiff差异比较

    1.安装mysql-utilities[root@localhost soft]# yum install  mysql-utilities.noarch 2.比较数据库zentao和数据库db_ze ...

  8. bat实现往hosts文件追加内容

    做个笔记. @echo off ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :::::::::::::::::::: ...

  9. 关于matplotlib绘制直方图偏移的问题

    在使用pyplot绘制直方图的时候我发现了一个问题,在给函数.hist()传参的时候,如果传入的组数不是刚刚好(就是说这个组数如果是使用(最大值-最小值)/组距计算出来,而这个数字不是整除得来而是取整 ...

  10. js函数式编程curry与compose实现

    //自行实现以下curry函数和compose //curry function curry(fn) { return function aa (...arg) { if (arg.length &g ...