HDU - 6341 多校4 Let Sudoku Rotate(状压dfs)
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
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?
Each test case consists of exactly 16 lines with 16 characters each, describing a broken sudoku.
681D5A0C9FDBB2F7
0A734B62E167D9E5
5C9B73EF3C208410
F24ED18948A5CA63
39FAED5616400B74
D120C4B7CA3DEF38
7EC829A085BE6D51
B56438F129F79C2A
5C7FBC4E3D08719F
AE8B1673BF42A58D
60D3AF25619C30BE
294190D8EA57264C
C7D1B35606835EAB
AF52A1E019BE4306
8B36DC78D425F7C9
E409492FC7FA18D2
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)的更多相关文章
- HDU 1565&1569 方格取数系列(状压DP或者最大流)
方格取数(2) Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total S ...
- hdu第4场j.Let Sudoku Rotate
Problem J. Let Sudoku Rotate Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Su ...
- HDU 5025:Saving Tang Monk(BFS + 状压)
http://acm.hdu.edu.cn/showproblem.php?pid=5025 Saving Tang Monk Problem Description <Journey to ...
- hdu 5977 Garden of Eden(点分治+状压)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5977 题解:这题一看就知道是状压dp然后看了一下很像是点分治(有点明显)然后就是简单的点分治+状压dp ...
- hdu 4049 2011北京赛区网络赛J 状压dp ***
cl少用在for循环里 #include<cstdio> #include<iostream> #include<algorithm> #include<cs ...
- hdu 4620 Fruit Ninja Extreme(状压+dfs剪枝)
对t进行从小到大排序(要记录ID),然后直接dfs. 剪枝的话,利用A*的思想,假设之后的全部连击也不能得到更优解. 因为要回溯,而且由于每次cut 的数目不会超过10,所以需要回溯的下标可以利用一个 ...
- hdu 4352 "XHXJ's LIS"(数位DP+状压DP+LIS)
传送门 参考博文: [1]:http://www.voidcn.com/article/p-ehojgauy-ot.html 题解: 将数字num字符串化: 求[L,R]区间最长上升子序列长度为 K ...
- hdu 3001 Travelling (三进制)【状压dp】
<题目链接> 题目大意: 给出n个点和m条边,求经过所有点所需的最小花费,每个点最多经过两次. 解题分析: TSP问题类型,由于此题每个点有三种状态,所以采用三进制状态压缩,0.1.2 分 ...
- 牛客多校3 A-PACM Team(状压降维+路径背包)
PACM Team 链接:https://www.nowcoder.com/acm/contest/141/A来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144 ...
随机推荐
- 原型模式 private static Map<String,Prototype> map = new HashMap<String,Prototype>();
public class PrototypeManager { /** * 用来记录原型的编号和原型实例的对应关系 */ private static Map<String,Prototype& ...
- visio_action
bug---沟通效率不能为负值!! https://blogs.office.com/en-us/2012/11/05/containers-and-callouts-in-visio/?eu=tru ...
- JavaScript如何判断非空
JavaScript判断非空的语句一般为: var elvis; if (typeof elvis !== "undefined" && elvis !== nul ...
- 【题解】DZY Loves Chinese
[题解]DZY Loves Chinese II 不吐槽这题面了... 考虑如何维护图的连通性,如果把图的变成一颗的\(dfs\)生成树,那么如果把一个节点的父边和他接下来所有的返祖边删除,那么我们就 ...
- WordPress升级出现Briefly unavailable for scheduled maintenance. Check back in a minute.
WordPress升级出现Briefly unavailable for scheduled maintenance. Check back in a minute. 打开博客时提示: Brief ...
- Oozie-1-安装、配置 让Hadoop流动起来
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/wl101yjx/article/details/27881739 写在前面一: 本文总结 基于Had ...
- maven 手动安装本地jar包
1.需要知道groupId.artifactId.version通过 cmd命令行执行 mvn install:install-file ,比如安装sigar.jar如下: mvn install:i ...
- Java for LeetCode 127 Word Ladder
Given two words (beginWord and endWord), and a dictionary, find the length of shortest transformatio ...
- Java for LeetCode 105 Construct Binary Tree from Preorder and Inorder Traversal
Given preorder and inorder traversal of a tree, construct the binary tree. Note: You may assume that ...
- fragment 动态加载
/** * 测试使用Fragment(动态使用) 1. * 使用FragmentManager和FragmentTransaction动态使用一个Fragment 2. 方式: * add(viewI ...