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. 淘宝(新浪)API获取IP地址位置信息

    package com.parse; import java.io.BufferedReader; import java.io.DataOutputStream; import java.io.IO ...

  2. UIWebview加载H5界面侧滑返回上一级

    一.UIWebview的发现 问题发现:当UIWebview王深层次点击的时候,返回时需要webView执行goBack方法一级一级返回,这样看到的webView只是在该界面执行刷新,并看不到类似iO ...

  3. NinjaFramework中文教程(简单版)-手把手教程-从零开始

    第一步: 官网http://www.ninjaframework.org/documentation/getting_started/create_your_first_application.htm ...

  4. python基础教程_学习笔记11:魔法方法、属性和迭代器

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/signjing/article/details/31417309 魔法方法.属性和迭代器 在pyth ...

  5. 特殊例子--JavaScript代码实现图片循环滚动效果

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  6. 【linux】在linux挂在windows共享目录

    mount -t cifs -o username=用户名,password='密码',vers=2.0 //windows共享目录 /linux挂载目录

  7. Java for LeetCode 126 Word Ladder II 【HARD】

    Given two words (start and end), and a dictionary, find all shortest transformation sequence(s) from ...

  8. re.sub用法

    re.sub功能是对于一个输入的字符串,利用正则表达式,来实现字符串替换处理的功能返回处理后的字符串 re.sub共有五个参数 三个必选参数pattern,repl,string 两个可选参数coun ...

  9. yum安装软件出错解决方法

    造成yum下载安装时语法出错, 一般是由于python多个版本共存的原因.所以,只需将yum 设置文件固定python 版本,也就是python2 下面的操作能解决版本冲突问题. 1.sudo vim ...

  10. PAT 甲级 1028. List Sorting (25) 【结构体排序】

    题目链接 https://www.patest.cn/contests/pat-a-practise/1028 思路 就按照 它的三种方式 设计 comp 函数 然后快排就好了 但是 如果用 c++ ...