Problem J. Let Sudoku Rotate

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 0    Accepted Submission(s): 0

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 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?

 
Input
The first line of the input contains an integer T (1≤T≤103) denoting the number of test cases.
Each test case consists of exactly 16 lines with 16 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
1
681D5A0C9FDBB2F7
0A734B62E167D9E5
5C9B73EF3C208410
F24ED18948A5CA63
39FAED5616400B74
D120C4B7CA3DEF38
7EC829A085BE6D51
B56438F129F79C2A
5C7FBC4E3D08719F
AE8B1673BF42A58D
60D3AF25619C30BE
294190D8EA57264C
C7D1B35606835EAB
AF52A1E019BE4306
8B36DC78D425F7C9
E409492FC7FA18D2
 
Sample Output
5

Hint

The original sudoku is same as the example in the statement.

 

Statistic | Submit | Clarifications | Back

#include <bits/stdc++.h>

const int MAX = ;
const int INF = 0x3f3f3f3f;
typedef long long ll; char s[MAX][MAX];
int b[MAX][MAX],h[MAX],l[MAX]; ll minn; int huan(char c){
if(''<=c&&c<='') return c-'';
return c-'A'+;
}
int biao(int x,int y,int k){
int i,j,ii,jj;
int xb=x%*;
int yb=y%*;
if(k==){
for(i=xb;i<xb+;i++){
for(j=yb;j<yb+;j++){
if(h[i]&(<<huan(s[i][j]))) return ;
if(l[j]&(<<huan(s[i][j]))) return ;
}
}
for(i=xb;i<xb+;i++){
for(j=yb;j<yb+;j++){
h[i]|=<<huan(s[i][j]);
l[j]|=<<huan(s[i][j]);
}
}
}
else if(k==){
for(j=yb+,ii=xb;j>=yb;j--,ii++){
for(i=xb,jj=yb;i<xb+;i++,jj++){
if(h[ii]&(<<huan(s[i][j]))) return ;
if(l[jj]&(<<huan(s[i][j]))) return ;
}
}
for(j=yb+,ii=xb;j>=yb;j--,ii++){
for(i=xb,jj=yb;i<xb+;i++,jj++){
h[ii]|=<<huan(s[i][j]);
l[jj]|=<<huan(s[i][j]);
}
}
}
else if(k==){
for(i=xb+,ii=xb;i>=xb;i--,ii++){
for(j=yb+,jj=yb;j>=yb;j--,jj++){
if(h[ii]&(<<huan(s[i][j]))) return ;
if(l[jj]&(<<huan(s[i][j]))) return ;
}
}
for(i=xb+,ii=xb;i>=xb;i--,ii++){
for(j=yb+,jj=yb;j>=yb;j--,jj++){
h[ii]|=<<huan(s[i][j]);
l[jj]|=<<huan(s[i][j]);
}
}
}
else{
for(j=yb,ii=xb;j<yb+;j++,ii++){
for(i=xb+,jj=yb;i>=xb;i--,jj++){
if(h[ii]&(<<huan(s[i][j]))) return ;
if(l[jj]&(<<huan(s[i][j]))) return ;
}
}
for(j=yb,ii=xb;j<yb+;j++,ii++){
for(i=xb+,jj=yb;i>=xb;i--,jj++){
h[ii]|=<<huan(s[i][j]);
l[jj]|=<<huan(s[i][j]);
}
}
}
return ;
} void shan(int x,int y,int k){
int i,j,ii,jj;
int xb=x%*;
int yb=y%*;
if(k==){
for(i=xb;i<xb+;i++){
for(j=yb;j<yb+;j++){
h[i]^=<<huan(s[i][j]);
l[j]^=<<huan(s[i][j]);
}
}
}
else if(k==){
for(j=yb+,ii=xb;j>=yb;j--,ii++){
for(i=xb,jj=yb;i<xb+;i++,jj++){
h[ii]^=<<huan(s[i][j]);
l[jj]^=<<huan(s[i][j]);
}
}
}
else if(k==){
for(i=xb+,ii=xb;i>=xb;i--,ii++){
for(j=yb+,jj=yb;j>=yb;j--,jj++){
h[ii]^=<<huan(s[i][j]);
l[jj]^=<<huan(s[i][j]);
}
}
}
else{
for(j=yb,ii=xb;j<yb+;j++,ii++){
for(i=xb+,jj=yb;i>=xb;i--,jj++){
h[ii]^=<<huan(s[i][j]);
l[jj]^=<<huan(s[i][j]);
}
}
}
}
void dfs(int x,int ss){
int i,j,k;
if(ss>=){
if(x<minn) minn=x;
return;
}
for(i=;i<;i++){
for(j=;j<;j++){
if(b[i][j]==){
for(k=;k<;k++){
if(!biao(i,j,k)) continue;
b[i][j]=;
dfs(x+k,ss+);
shan(i,j,k);
b[i][j]=;
}
return;
}
}
}
} int main(void)
{
int t,n,i;
scanf("%d",&t);
while(t--){
for(i=;i<;i++){
scanf(" %s",s[i]);
}
minn=;
dfs(,);
printf("%d\n",minn);
}
return ;
}

HDU - 6341 多校4 Let Sudoku Rotate(状压dfs)的更多相关文章

  1. HDU 1565&1569 方格取数系列(状压DP或者最大流)

    方格取数(2) Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total S ...

  2. hdu第4场j.Let Sudoku Rotate

    Problem J. Let Sudoku Rotate Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Su ...

  3. HDU 5025:Saving Tang Monk(BFS + 状压)

    http://acm.hdu.edu.cn/showproblem.php?pid=5025 Saving Tang Monk Problem Description   <Journey to ...

  4. hdu 5977 Garden of Eden(点分治+状压)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5977 题解:这题一看就知道是状压dp然后看了一下很像是点分治(有点明显)然后就是简单的点分治+状压dp ...

  5. hdu 4049 2011北京赛区网络赛J 状压dp ***

    cl少用在for循环里 #include<cstdio> #include<iostream> #include<algorithm> #include<cs ...

  6. hdu 4620 Fruit Ninja Extreme(状压+dfs剪枝)

    对t进行从小到大排序(要记录ID),然后直接dfs. 剪枝的话,利用A*的思想,假设之后的全部连击也不能得到更优解. 因为要回溯,而且由于每次cut 的数目不会超过10,所以需要回溯的下标可以利用一个 ...

  7. hdu 4352 "XHXJ's LIS"(数位DP+状压DP+LIS)

    传送门 参考博文: [1]:http://www.voidcn.com/article/p-ehojgauy-ot.html 题解: 将数字num字符串化: 求[L,R]区间最长上升子序列长度为 K ...

  8. hdu 3001 Travelling (三进制)【状压dp】

    <题目链接> 题目大意: 给出n个点和m条边,求经过所有点所需的最小花费,每个点最多经过两次. 解题分析: TSP问题类型,由于此题每个点有三种状态,所以采用三进制状态压缩,0.1.2 分 ...

  9. 牛客多校3 A-PACM Team(状压降维+路径背包)

    PACM Team 链接:https://www.nowcoder.com/acm/contest/141/A来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144 ...

随机推荐

  1. native2ascii转码工具的使用

    native2ascii转码工具是JDK自带的一种,方便我们将非unicode的编码文件转为unicode格式的文件,位置一般是位于JAVA_HOME/bin目录下. Why? 在做Java开发的时候 ...

  2. ios Symbol(s) not found for architecture arm64总结 含隐藏错误cocoapods

    一.通用 报错:Desktop/project/ASDF/WEIXIN/libWeChatSDK.a (3 slices) Undefinedsymbols for architecture arm6 ...

  3. 《Linux 鸟哥私房菜》 第6章 Linux的文件权限与目录配置

    1.文件的类型与权限. 如图红框.权限与类型共有10个字符组成. (1)第一个字符代表这个文件是“目录.文件或链接文件等”. [d]则是目录 [-]则是文件 [|]则是连接文件 [b]则是设备文件里面 ...

  4. maven-appfuse配备步骤

    版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/qiaqia609/article/details/36231851 maven-appfuse配置步 ...

  5. Python实现简易HTTP服务器

    一.Python3 搭建简易HTTP服务器 python -m http.server 浏览器访问:http://localhost:8000 Python3 cgiserver python -m  ...

  6. BZOJ 2142 礼物 数论

    这道题是求组合数终极版. C(n,m) mod P n>=1e9 m>=1e9 P>=1e9且为合数且piqi<=1e5 拓展lucas定理. 实际上就是一点数论小知识的应用. ...

  7. 使用CL命令编译cpp文件

    缘起,我的vs 2003无法新建工程,又不喜欢用vs 2013那样的重量级开发工具(就写两行代码,测试测试一些基本的语法规则或算法). 想来vs应该可以像GCC或G++那样直接用命令行编译Cpp文件, ...

  8. Windows内存性能分析(二)性能瓶颈

    内存瓶颈: 由于可用内存缺乏导致系统性能下降的现像. (一).相关的性能对象 主要考虑内存的页面操作和磁盘的I/O操作,需要考虑如下性能对象: Memory性能对象: 用于分析整个系统的内存瓶颈问题. ...

  9. openfire性能测试

    使用TSung对Jabber服务器openfire进行压力测试 http://blog.csdn.net/spider_zhcl/article/details/6073920 Tsung负载测试Ti ...

  10. 详解 pthread_detach()函数

    pthread_t 类型定义: typedef unsigned long int pthread_t; //come from /usr/include/bits/pthread.h 用途:pthr ...