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. 1.字符串操作:& 2.英文词频统计预处理

    1.字符串操作: 解析身份证号:生日.性别.出生地等. ID = input('请输入十八位身份证号码: ') if len(ID) == 18: print("你的身份证号码是 " ...

  2. 高校表白APP-冲刺第四天

    第四天,我们进行了团队的的四次会议. 一.任务: 昨天任务:完成登录界面注册界面修改密码界面. 今日任务:完成跳转,并解决闪退问题. 明日任务:连接本地数据库,进行APP的第一次登陆. 二.遇到的困难 ...

  3. 小米手机跨域问题,返回resphone:undefined,status 0

    小米手机跨域问题,返回resphone:undefined,status 0我小米note2的手机登录不上,返回resphone:undefined,status 0 我手机登录不了的问题解决了,后台 ...

  4. 打开visual studio 2010报错:未能正确加载“VSTS for Database Professionals Sql Server Data-tier Application”包

    1  解决: 运行cmd 2  输入:regsvr32 %windir%\system32\jscript.dll

  5. jvm启动参数设置 -Dfile.encoding=UTF-8 解决freemark乱码

    今天一个spring boot应用windows跑起来后页面显示乱码,加上jvm启动参数为utf-8后,页面显示正常.

  6. 终于有人把云计算、大数据和 AI 讲明白了

    最近学习hadoop以及生态,顺便看到了这篇文章,总结的很到位,转载下. 我今天要讲这三个话题,一个是云计算,一个大数据,一个人工智能,我为什么要讲这三个东西呢?因为这三个东西现在非常非常的火,它们之 ...

  7. @Override报错的处理

    有时候我们从SVN导的项目,jre和jar包都没问题,但是就会出如下图的错误: xi 点击红叉,显示错误信息如下: 点击工具里面的window-->preferences-->java-- ...

  8. git checkout --ours 【学习笔记】

    用新分支:git checkout --theirs 文件用master分支:git checkout --ours 文件 执行之后git add

  9. [IoC容器Unity]第四回:使用范例

    1.引言 前面几个章节介绍了Unity的基本使用,主要分为程序和配置文件两种方法的使用,可以参考一下链接, [IoC容器Unity]第一回:Unity预览 [IoC容器Unity]第二回:Lifeti ...

  10. Vue-admin工作整理(三):路由

    1.router-link和router-view组件 router-link组件实际上是封装了一个a标签(链接标签),里面有一个重要属性:“to”,它的值是一个路径,其路径对应的渲染组件,要在路由列 ...