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. 解决集群搭建找不到datanode的问题

    解决"no datanode to stop"问题当我停止Hadoop时发现如下信息:    no datanode to stop原因:每次namenode format会重新创 ...

  2. a positive definite matrix

    https://en.wikipedia.org/wiki/Definite_quadratic_form https://www.math.utah.edu/~zwick/Classes/Fall2 ...

  3. 【总结】图论小总结【题解】P1330封锁阳关大学

    [题解][总结]P1330 封锁阳光大学 &&图论小总结 这道题其实有一点点难度,不过我能经过思考做出来说明还是没有普及组\(D1T1\)难度的. 考虑一条边的两边要有且仅有一个点被选 ...

  4. BZOJ1217: [HNOI2003]消防局的设立

    BZOJ1217: [HNOI2003]消防局的设立 Description 2020年,人类在火星上建立了一个庞大的基地群,总共有n个基地. 起初为了节约材料,人类只修建了n-1条道路来连接这些基地 ...

  5. imagick图片压缩。

    选择一个合适的图片处理扩展包. 常见的扩展如GD,imagick,Gmagick. 老古董的GD丢掉吧,效率很低,而且压缩的图片体积很大=.=   imagick是个不错的选择,在PHP的图片处理扩展 ...

  6. Java for LeetCode 104 Maximum Depth of Binary Tree

    Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the long ...

  7. RaspBerry Pi3 ~ 内核编译

    RaspBerryPi3-内核编译 转载注明出处:http://www.cnblogs.com/einstein-2014731/p/5985128.html 在有道云笔记的同步分享:http://n ...

  8. DOM的介绍

    一 . DOM 介绍 什么是DOM DOM:文档对象模型.DOM 为文档提供了结构化表示,并定义了如何通过脚本来访问文档结构.目的其实就是为了能让js操作html元素而制定的一个规范. DOM就是由节 ...

  9. CodeForces - 922E Birds —— DP

    题目链接:https://vjudge.net/problem/CodeForces-922E E. Birds time limit per test 1 second memory limit p ...

  10. ios图片瀑布流代码

    ios瀑布流,实现简单的瀑布流视图布局,可以显示网络图片,下拉刷新,上拉加载更多. 下载:http://www.huiyi8.com/sc/9087.html