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 ...
随机推荐
- 在调用Response.End()时,会执行Thread.CurrentThread.Abort()操作
在调用Response.End()时,会执行Thread.CurrentThread.Abort()操作. 如果将Response.End()放在try...catch中,catch会捕捉Thread ...
- sed相关
1 global flag sed 's/xxx/xxx/' inputfile,如果没有带global flag g的话,匹配替换的只是inputfile中的每一行的第一个匹配项.如果带了g的话,才 ...
- 洛谷2483 k短路([SDOI2010]魔法猪学院)
题目请戳这里 一句话题意: 给你一张n个节点,m条单向边的图,求1到n第k短的路. emmm,纪念第一个黑题(我是真的菜啊!!) 这题目还是很难的,本蒟蒻只会被洛谷卡掉的A(所以就愉快地特判了),首先 ...
- .net 调用SAP RFC的几种方法
转自:http://www.cherpservice.com/pub/newsdetail.asp?Newsid=3613 第一种方式采用SAP.net Connector: 最新版本是3.,不开源, ...
- debug x86 汇编程序指南
--------------------------------------------------------------------------------------------------- ...
- POJ - 1426 Find The Multiple 【DFS】
题目链接 http://poj.org/problem?id=1426 题意 给出一个数 要求找出 只有 0 和 1 组成的 十进制数字 能够整除 n n 不超过 200 十进制数字位数 不超过100 ...
- AppStore App申请审核加速
容芳志大牛一直是我学习的榜样 分类: iOS开发经验技巧2014-11-12 09:40 409人阅读 评论(0) 收藏 举报 有没有遇到上线后发现很严重的bug这种情况,修复bug后提交审核又是漫长 ...
- WPF区时浏览小程序
在深圳已经工作了一个月了,之前做WinForm的,现在做WPF,每天加班到晚上10点,比之前累.学习新技术也是有个过程的,我就从基础的语法和 界面布局做起.这是我仿着做一个小软件. 效果图赏析 在原基 ...
- php中一些比常见做法更好的实践
有些被我们习以为常的做法未必就是最好的,它们可能存在一些安全问题,而解决这些隐患的成本,其实并不高: 密码 常见做法是直接MD5进行加密,比如这样: //加密 $passwordStr = md5($ ...
- tensorflow学习官网地址
摘自: http://wiki.jikexueyuan.com/project/tensorflow-zh/tutorials/overview.html 内容很多,需要花时间看完