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和之前枚举的已经满足条件的块, ...
随机推荐
- 运行npm安装wepy2踩坑error EEXIST 问题
windows 10安装wepy2 以前用过wepy1,现在要学习wepy2,运行以下命令出错 npm install @wepy/cli -g # 全局安装 WePY CLI 工具 打开log文件, ...
- Prism+MaterialDesign+EntityFramework Core+Postgresql WPF开发总结 之 中级篇
本着每天记录一点成长一点的原则,打算将目前完成的一个WPF项目相关的技术分享出来,供团队学习与总结. 总共分三个部分: 基础篇主要争对C#初学者,巩固C#常用知识点: 中级篇主要争对WPF布局与Mat ...
- QT-day1 创建项目
- JDK+maven安装
JDK+Maven安装汇总: 1.JDK1.8: 链接:https://pan.baidu.com/s/1d04iZagXqzG-DoGV5oUFug 提取码:bd1m Maven3.6.3: 链接: ...
- python 入门 之 Json 序列化
开发网站,离不了Json 但是一般情况,不支持python的其它对象,怎么办? 有办法:Json 序列化!!! 总体来说,需要序列化的数据类型为 字典,类,嵌套类. 下面是我做的一个demo,都包含了 ...
- 10.6 IoStudentManager
package day11_io_student.student_demo; public class Student { private String id; private String name ...
- String 对象-->toLowerCase() 方法
1.定义和用法 将字符串中所有的大写字符转换成小写字符,小写字符不变 返回转换后的结果字符串 语法: string.toLowerCase() 注意:不会改变字符串本身,仅以返回值的形式返回结果 举例 ...
- python3(二十二) oop
""" 面向对象编程 """ __author__ = 'shaozhiqi' # 面向对象的程序设计把计算机程序视为一组对象的集合,而每个 ...
- 来说说Java中String 类的那些事情
今天正好学校那边的任务不多,我就打算把Stirng 的有关知识点都总结在一起了,这样有利于知识的系统性,要不然学多了就会越来越杂,最主要的是总会忘记,记忆的时间太短了,通过这种方式,把它归纳在一起,写 ...
- pgsql中json格式数组查询结果变成了字符串
场景复原 最近使用到了json的数组,用来存储多个文件的值,发现在连表查询的时候返回结果变成了字符串. { "id": "repl-placeholder-007&quo ...