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,如果变量还不用全局变量的话连内存 ...
随机推荐
- Oarcle 之连接查询
连接查询:连接查询是关系数据库中最主要的查询,主要包括内连接.外连接和交叉连接等.通过连接运算符可以实现多个表查询.连接是关系数据库模型的主要特点,也是它区别于其它类型数据库管理系统的 ...
- 顶尖 API 文档管理工具 (Yapi)
原文地址:https://www.jianshu.com/p/a97d2efb23c5
- iOS进阶之UDP代理鉴权过程
上一篇介绍的是TCP代理的鉴权过程,这篇将介绍UDP代理的大致鉴权过程. 在UDP鉴权过程中,有几点是需要注意的.首先,UDP是一种无连接协议,不需要连接,使用广播的方式:其次,为了通过鉴权,所以需要 ...
- Flutter数据库Sqflite之增删改查
Flutter数据库Sqflite之增删改查 简介 sqflite是Flutter的SQLite插件,支持iOS和Android,目前官方版本是sqflite1.1.3 sqflite插件地址:h ...
- Tomcat在Window控制台下启动时乱码的两种解决办法
在命令提示符中启动Tomcat时,日志窗口出现乱码: 乱码的原因肯定是日志解码错误引起的,因此就有一系列问题: 1.这个窗口的文本编码是什么? 窗口的文本编码查看:右击窗口>选项 可以看到窗口的 ...
- qt连接数据库Sqlite
#include <QCoreApplication> #include <QDebug> #include <QSqlDatabase> #include < ...
- Cent OS6下SS+BBR+改SSH端口
SS+BBR+改SSH端口 (一)搭建SS wget --no-check-certificate -O shadowsocks-libev.sh https://raw.githubusercont ...
- 使用tp访问数据库时提示错误: 'PDO' not found, 和not defined constant mysql_attr_init_command 和call an undefined function Think\Template\simpleXml_load_string()函数
第一个问题: PDO not found 是因为 php没有安装pdo扩展, 无法提供给 php 以 数据库访问功能, 所以 报错是在文件: Think/Db.class.php的里面. 解决方法是: ...
- java 随机出题四则运算
作业要求来源于:https://edu.cnblogs.com/campus/gzcc/GZCC-16SE2/homework/2186 我的github地址:https://github.com/k ...
- [转载]解决"command 'gcc' failed with exit status 1"错误问题
转自:https://blog.csdn.net/learn_tech/article/details/80066583 解决"command 'gcc' failed with exit ...