HDU 6341 Let Sudoku Rotate
#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的更多相关文章
- HDU - 6341 多校4 Let Sudoku Rotate(状压dfs)
Problem J. Let Sudoku Rotate Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K ...
- hdu第4场j.Let Sudoku Rotate
Problem J. Let Sudoku Rotate Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Su ...
- 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 ...
- HDU暑假多校第四场J-Let Sudoku Rotate
一.题意 Sudoku is a logic-based, combinatorial number-placement puzzle, which is popular around the wor ...
- 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 ...
- (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 ...
- (中等) 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 ...
- hdu6341 Problem J. Let Sudoku Rotate (dfs)
题目传送门 题意: 给你16个16宫格的数独,里面是0~F,你可以逆时针旋转里面的每个16宫格 问你它是从标准数独逆时针旋转多少次得到? 思路: 可以知道每个16宫已经是标准的了,接下来只要考虑每行. ...
- HDU6341 Let Sudoku Rotate (杭电多校4J)
给一个由4*4个4*4的小格组成数独,这些数独是由一个块逆时针旋转得来的,所以要还原的话就模拟出顺时针的过程,先把里面的字母转化成数字,然后从第一个块开始枚举,每个dfs和之前枚举的已经满足条件的块, ...
随机推荐
- python学习笔记--字符串格式化
字符串和常量 print(r'hello\py\thon') r 代表后面字符不进行转义,原样输出; 表示常量,命名时变量名字大写代表常量.NAME = 'liulixue'; 字符串表示:' ', ...
- .git/info/refs not valid: is this a git repository?
今天用idea git提交的时候遇到了这个神奇的问题.git/info/refs not valid: is this a git repository? 看了很多网上的都不靠谱,最后自己乱点着找, ...
- 使用onclick/表单submit跳转到其他页面
使用onclick 如果是本页显示可以直接用location,方法如下: - onclick="javascript:window.location.href='URL'" - o ...
- Vue设置路由跳转的两种方法: <router-link :to="..."> 和router.push(...)
一.<router-link :to="..."> to里的值可以是一个字符串路径,或者一个描述地址的对象.例如: // 字符串 <router-link to= ...
- 计算机人推荐书目&网站(不断更新)
计算机人推荐书目&网站(不断更新) 鉴于最近有很多同学问我学什么读什么书好,我把我自己的经历和愚见写下来,仅供参考.我只会写我亲自读过有感悟的书,而不会搬运一些我碰都没有碰过只闻大名的书.本人 ...
- Centos网络的配置
...
- 最近准备研读thinkphp源码,ctag派上用场了
本人习惯用vim编辑器,这里ctags配置vim很方便. #在ThinkPHP源码目录(假定为/server/thinkphp)执行: $ cd /server/thinkphp $ ctags -R ...
- php--phpstudy更新数据库版本后,无法一键启动
只需输入以下命令即可: sc delete mysql
- spring03
学习了spring的数据源的使用以及spring的作用域引入外部属性文件 对应的bean的xml文件和properties文件如下 <?xml version="1.0" e ...
- 【java设计模式】(7)---策略模式(案例解析)
策略模式 一.概念 1.理解策略模式 策略模式是一种行为型模式,它将对象和行为分开,将行为定义为 一个行为接口 和 具体行为的实现.策略模式最大的特点是行为的变化,行为之间可以相互替换. 每个if判断 ...