#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define ms(arr,a) memset(arr,a,sizeof arr)
#define debug(x) cout<<"< "#x" = "<<x<<" >"<<endl
char s[16][17],tmp[4][5];
void rot(int x,int y)
{
for(int i=0;i<4;++i)
for(int j=0;j<4;++j)
tmp[i][j]=s[4*x-1-j][4*y-4+i];
for(int i=0;i<4;++i)
for(int j=0;j<4;++j)
s[4*x-4+i][4*y-4+j]=tmp[i][j];
}
bool judge(int x,int y)
{
int a[20];
for(int i=4*x-4;i<4*x;++i)
{
ms(a,0);
for(int j=0;j<4*y;++j)
{
if(a[s[i][j]]>0)return false;
a[s[i][j]]++;
}
}
for(int i=4*y-4;i<4*y;++i)
{
ms(a,0);
for(int j=0;j<4*x;++j)
{
if(a[s[j][i]]>0)return false;
a[s[j][i]]++;
}
}
return true;
}
int ans;
void dfs(int x,int y,int now)
{
if(now>=ans)return;
if(x==5){ans=min(ans,now);return;}
if(y==5){dfs(x+1,1,now);return;}
for(int i=0;i<4;++i)
{
if(judge(x,y))dfs(x,y+1,now+i);
rot(x,y);
}
}
int main()
{
int T;scanf("%d",&T);
while(T--)
{
ans=100;
for(int i=0;i<16;++i)scanf("%s",s[i]);
for(int i=0;i<16;++i)
for(int j=0;j<16;++j)
{
if(isdigit(s[i][j]))s[i][j]-=48;
else s[i][j]-=55;
}
dfs(1,1,0);
printf("%d\n",ans);
}
}

HDU 6341 Let Sudoku Rotate的更多相关文章

  1. HDU - 6341 多校4 Let Sudoku Rotate(状压dfs)

    Problem J. Let Sudoku Rotate Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K ...

  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. 2018 Multi-University Training Contest 4 Problem J. Let Sudoku Rotate 【DFS+剪枝+矩阵旋转】

    任意门:http://acm.hdu.edu.cn/showproblem.php?pid=6341 Problem J. Let Sudoku Rotate Time Limit: 2000/100 ...

  4. HDU暑假多校第四场J-Let Sudoku Rotate

    一.题意 Sudoku is a logic-based, combinatorial number-placement puzzle, which is popular around the wor ...

  5. HDU 4069 Squiggly Sudoku(DLX)(The 36th ACM/ICPC Asia Regional Fuzhou Site —— Online Contest)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4069 Problem Description Today we play a squiggly sud ...

  6. (hdu)5547 Sudoku (4*4方格的 数独 深搜)

    Problem Description Yi Sima was one of the best counselors of Cao Cao. He likes to play a funny game ...

  7. (中等) HDU 4069 Squiggly Sudoku , DLX+精确覆盖。

    Description Today we play a squiggly sudoku, The objective is to fill a 9*9 grid with digits so that ...

  8. hdu6341 Problem J. Let Sudoku Rotate (dfs)

    题目传送门 题意: 给你16个16宫格的数独,里面是0~F,你可以逆时针旋转里面的每个16宫格 问你它是从标准数独逆时针旋转多少次得到? 思路: 可以知道每个16宫已经是标准的了,接下来只要考虑每行. ...

  9. HDU6341 Let Sudoku Rotate (杭电多校4J)

    给一个由4*4个4*4的小格组成数独,这些数独是由一个块逆时针旋转得来的,所以要还原的话就模拟出顺时针的过程,先把里面的字母转化成数字,然后从第一个块开始枚举,每个dfs和之前枚举的已经满足条件的块, ...

随机推荐

  1. NKOJ3777 卡牌操作

    问题描述 有n张卡片在桌上一字排开,每张卡片上有两个数,第i张卡片上,正面的数为a[i],反面的数为b[i].现在,有m个熊孩子来破坏你的卡片了!第i个熊孩子会交换c[i]和d[i]两个位置上的卡片. ...

  2. # H - H HDU - 2066 (多起点、多终点问题)

    H - H HDU - 2066 (多源点.多汇点问题) 一个图上,有M条边,Z个出发点,Y个终止点.求一条最短路,其中起点是Z中的任意一点,终点是Y中任意一点. Input 输入数据有多组,输入直到 ...

  3. A - Jessica's Reading Problem POJ - 3320 尺取

    A - Jessica's Reading Problem POJ - 3320 Jessica's a very lovely girl wooed by lots of boys. Recentl ...

  4. css进阶选择器

    后代选择器 用空格隔开 选择div标签下的p标签下的a标签 div p a 选择class为parent标签下的p标签下的a标签 .parent p a 后代选择器可以是标签.类.id的混合体 后代选 ...

  5. 简单分析ucenter 会员同步登录通信原理

    1.用户登录discuz,通过logging.php文件中的函数uc_user_login对post过来的数据进行验证,也就是对username和password进行验证. 2.如果验证成功,将调用位 ...

  6. Python 1基础语法二(标识符、关键字、变量和字符串)

    一.标识符 标识符就是程序员自己命名的变量名.名字需要有见名知义的效果,不要随意起名 :比如 a=1 a是个变量,a这个变量名属于标识符 1 company = '小米 2 employeeNum = ...

  7. 28.6 Integer 自动装箱和拆箱

    public class IntegerDemo2 { public static void main(String[] args) { //自动装箱 // Integer i = new Integ ...

  8. Python操作rabbitmq系列(四):根据类型订阅消息

    在上一章中,所有的接收端获取的所有的消息.这一章,我们将讨论,一些消息,仍然发送给所有接收端.其中,某个接收端,只对其中某些消息感兴趣,它只想接收这一部分消息.如下图:C1,只对error感兴趣,C2 ...

  9. python 集合(set)和字典(dictionary)的用法解析

    Table of Contents generated with DocToc ditctaionary and set hash 介绍 集合-set 创建 操作和访问集合的元素 子集.超集.相对判断 ...

  10. 360众测考试,weblogic题(CVE-2018-2894)文件上传漏洞

    0x01 漏洞简介 Weblogic管理端未授权的两个页面存在任意上传jsp文件漏洞,进而获取服务器权限. Oracle 7月更新中,修复了Weblogic Web Service Test Page ...