UESTC - 1222 Sudoku(深搜)
Yi Sima was one of the best counselors of Cao Cao. He likes to play a funny game himself. It looks like the modern Sudoku, but smaller.
Actually, Yi Sima was playing it different. First of all, he tried to generate a 4×44×4 board with every row contains 11 to 44 , every column contains 11 to 44 .
Also he made sure that if we cut the board into four 2×22×2
pieces, every piece contains 11
to 44
.
Then, he removed several numbers from the board and gave it to another guy to recover it. As other counselors are not as smart as Yi Sima, Yi Sima always made sure that the
board only has one way to recover.
Actually, you are seeing this because you've passed through to the Three-Kingdom Age. You can recover the board to make Yi Sima happy and be promoted. Go and do it!!!
Input
The first line of the input gives the number of test cases, TT
(1≤T≤1001≤T≤100
). TT
test cases follow. Each test case starts with an empty line followed by 44
lines.
Each line consist of 44
characters. Each character represents the number in the corresponding cell (one of 1, 2, 3, 4). * represents that number was removed by Yi Sima.
It's guaranteed that there will be exactly one way to recover the board.
Output
For each test case, output one line containing Case #x:, where xx
is the test case number (starting from 11
).
Then output 44
lines with 44
characters each. indicate the recovered board.
Sample Input
3 ****
2341
4123
3214 *243
*312
*421
*134 *41*
**3*
2*41
4*2*
Sample Output
Case #1:
1432
2341
4123
3214
Case #2:
1243
4312
3421
2134
Case #3:
3412
1234
2341
4123
题意:一个4*4的矩阵,满足每个数的同行同列都由1234构成的,把4*4矩阵分成4个2*2矩阵,每个矩阵的四个元素也分别
为1234。
这题就是暴力深搜。
ac代码:
1 #include<cstdio>
2 #include<cstring>
3 #define Max 8
4 char st[Max][Max];
5 int judg(int x,int y,char i) //判断当前位置可以是什么数字
6 {
7 if(x<3&&y<3)
8 {
9 if(st[1][1]==i||st[1][2]==i||st[2][1]==i||st[2][2]==i)
10 return 0;
11 }
12 else if(x<3&&y>2)
13 {
14 if(st[1][3]==i||st[1][4]==i||st[2][3]==i||st[2][4]==i)
15 return 0;
16 }
17 else if(x>2&&y<3)
18 {
19 if(st[3][1]==i||st[3][2]==i||st[4][1]==i||st[4][2]==i)
20 return 0;
21 }
22 else if(x>2&&y>2)
23 {
24 if(st[3][3]==i||st[3][4]==i||st[4][3]==i||st[4][4]==i)
25 return 0;
26 }
27 for(int k=1;k<=4;k++)
28 {
29 if(st[x][k]==i||st[k][y]==i)
30 return 0;
31 }
32 return 1;
33 }
34 void dfs(int x,int y)
35 {
36 if(x==5)
37 {
38 for(int i=1;i<=4;i++)
39 printf("%s\n",st[i]+1);
40 return ;
41 }
42 if(st[x][y]!='*')
43 {
44 if(y==4)
45 dfs(x+1,1);
46 else
47 dfs(x,y+1);
48 }
49 else
50 {
51 for(int i=1;i<=4;i++)
52 {
53 if(judg(x,y,i+'0'))
54 {
55 st[x][y]=i+'0';
56 if(y==4)
57 dfs(x+1,1);
58 else
59 dfs(x,y+1);
60 st[x][y]='*'; //如果没有满足的则回溯
61 }
62 }
63 }
64 }
65 int main()
66 {
67 int t;
68 scanf("%d",&t);
69 getchar();
70 for(int i=1;i<=t;i++)
71 {
72 for(int j=1;j<=4;j++)
73 scanf("%s",st[j]+1);
74 printf("Case #%d:\n",i);
75 dfs(1,1);
76 }
77 return 0;
78 }
UESTC - 1222 Sudoku(深搜)的更多相关文章
- UESTC 1222 Sudoku
爆搜即可 /* *********************************************** author : email :523689985@qq.com created tim ...
- ACM学习历程—UESTC 1222 Sudoku(矩阵)(2015CCPC H)
题目链接:http://acm.uestc.edu.cn/#/problem/show/1226 题目大意就是构造一个行列和每个角的2*2都是1234的4*4矩阵. 用dfs暴力搜索,不过需要每一步进 ...
- 深搜+回溯 POJ 2676 Sudoku
POJ 2676 Sudoku Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 17627 Accepted: 8538 ...
- 数独(深搜)(poj2726,poj3074)
数独(深搜)数据最弱版本(poj 2676) Description Sudoku is a very simple task. A square table with 9 rows and 9 co ...
- HDU--杭电--1195--Open the Lock--深搜--都用双向广搜,弱爆了,看题了没?语文没过关吧?暴力深搜难道我会害羞?
这个题我看了,都是推荐的神马双向广搜,难道这个深搜你们都木有发现?还是特意留个机会给我装逼? Open the Lock Time Limit: 2000/1000 MS (Java/Others) ...
- 利用深搜和宽搜两种算法解决TreeView控件加载文件的问题。
利用TreeView控件加载文件,必须遍历处所有的文件和文件夹. 深搜算法用到了递归. using System; using System.Collections.Generic; using Sy ...
- 2016弱校联盟十一专场10.3---Similarity of Subtrees(深搜+hash、映射)
题目链接 https://acm.bnu.edu.cn/v3/problem_show.php?pid=52310 problem description Define the depth of a ...
- 2016弱校联盟十一专场10.2---Around the World(深搜+组合数、逆元)
题目链接 https://acm.bnu.edu.cn/v3/problem_show.php?pid=52305 problem description In ICPCCamp, there ar ...
- 2015暑假多校联合---Cake(深搜)
题目链接:HDU 5355 http://acm.split.hdu.edu.cn/showproblem.php?pid=5355 Problem Description There are m s ...
随机推荐
- 使用.net中的API网关模式封装微服务
在本文中,我们将了解如何使用API网关模式来封装微服务并抽象出底层实现细节,从而允许使用者拥有进入我们系统的一致入口点. 为了构建和测试我们的应用程序,我们需要: 1.Visual Studio 20 ...
- qt for webassembly环境搭建图文教程
一.前言 从Qt5.14开始,官方的在线安装提供了qt for webassembly构建套件,这对很多小白来说绝对是个好消息,也绝对是个好东西,好消息是不用再去交叉编译自己生成qt for weba ...
- 企业项目迁移go-zero全攻略(二)
承接上篇:上篇文章讲到 go-zero 架构设计和项目设计.本篇文章接着这个项目设计,将生成的 app 模块 中 gateway 和 RPC 进行改造.废话不多说,让我们开始! gateway ser ...
- SpringBoot配置文件基础部分说明
SpringBoot-yml文件配置说明 友情提示:有一些代码中有乱码,请脑补删除,适合快速入门 #开启spring的Bebug模式,可以查看有哪些自动配置生效 #debug=true #开启热启动, ...
- 使用eventfd创建一个用于事件通知的文件描述符
https://www.jianshu.com/p/57cc1d7d354f nat穿透代码c++
- 莫队/se 优雅的暴力
莫队算法 发明者:队爷莫涛 基于分块的一种暴力算法, 复杂度最慢可以被卡到\(n^2\)正常情况下的复杂度大约在\(O(n\sqrt{n})\)左右分块的大小对复杂的影响很大其中最优分块的大小为\(\ ...
- Jmeter(三十七) - 从入门到精通进阶篇 - 输出HTML格式的性能测试报告(详解教程)
1.简介 相对于Loadrunner,Jmeter其实也是可以有测试报告产出的,虽然一般都不用(没有Loadrunner的报告那么强大是一方面),但是有小伙伴们私下问,那宏哥还是顺手写一下吧,今天我们 ...
- js异步、事件循环(EventLoop)小结
单线程 众所周知,JS是单线程的语言,之所以是单线程,用一句烂大街的话就是,如果两个线程同时操作一个DOM节点,那么该以哪个为准呢,虽然多线程也有办法解决,但是js毕竟是浏览器脚本语言,不需要那么复杂 ...
- MySQL安装+初始化操作(1)
先去官网下载自己适合的版本,在这里我选择下载Windows 64位版本的,这是下载地址. 1.下载MySQL,步骤①==>步骤② 2.下载后,解压到除系统盘(C盘)之外的其他盘中 3.解压后在b ...
- 设计模式c++(2)——策略模式
策略模式定义了算法族,分别封装起来,让它们之间可以互相替换,此模式让算法的变化独立于使用算法的客体. 书上的例子是鸭子,参考blog的例子是缓存算法.参考blog见:https://blog.csdn ...