#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
using namespace std;
char s[10][10]; int panduan(int row,int cew)
{
for(int i=0;i<4;i++)
{
if(s[row][i]==s[row][cew]&&i!=cew) return 0;
}
for(int j=0;j<4;j++)
{
if(s[j][cew]==s[row][cew]&&j!=row) return 0;
}
int mrow=row;
int mcew=cew;
if(row%2==1) row--;
if(cew%2==1) cew--;
for(int i=row;i<row+2;i++)
{
for(int j=cew;j<cew+2;j++)
{
if(s[i][j]==s[mrow][mcew]&&i!=mrow&&j!=mcew) return 0;
}
}
return 1;
} void dfs(int step)
{
if(step==16)
{
for(int i=0;i<4;i++)
{
for(int j=0;j<4;j++)
{
printf("%c",s[i][j]);
}
printf("\n");
}
} int row=step/4;
int cew=step%4;
if(s[row][cew]=='*')
{
for(int j=1;j<=4;j++)
{
s[row][cew]=j+'0';
if(panduan(row,cew)) dfs(step+1);
s[row][cew]='*';
}
}
else dfs(step+1);
} int main()
{
int cas=0;
int t;
cin>>t;
while(t--)
{
for(int i=0;i<4;i++) scanf("%s",s[i]);
printf("Case #%d:\n",++cas);
dfs(0);
}
return 0;
}

  

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 1 to 4, every column contains 1 to 4. Also he made sure that if we cut the board into four 2×22×2 pieces, every piece contains 1 to 4.

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!!!

InputThe first line of the input gives the number of test cases, T(1≤T≤100)T(1≤T≤100). TT test cases follow. Each test case starts with an empty line followed by 4 lines. Each line consist of 4 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.OutputFor each test case, output one line containing
Case #x:, where xx is the test case number (starting from 1). Then output 4 lines with 4 characters each. indicate the recovered board.Sample Input

3
****
2341
4123
3214
*243
*312
*421 题目:B - Sudoku
思路:
这个题目其实就是一个小一点的数独,因为很小,所以可以用枚举去搜索,完全不用担心会超时。
方法很简单就是枚举每一个*位置为1,2,3,4;然后再回溯。
具体:
再main函数里面读入,然后进入搜索函数dfs,有一个step,如果step==16就结束了
根据step可以判断出行列,然后搜这个位置,如果是*就枚举,否则就step++,进入下一个dfs
注意要写一个数独的判断函数。

寒假集训——搜索 B - Sudoku的更多相关文章

  1. 寒假集训——搜索 D - Cubes for Masha

    #include <stdio.h> #include <stdlib.h> #include <iostream> #include <string.h&g ...

  2. CSU-ACM寒假集训选拔-入门题

    CSU-ACM寒假集训选拔-入门题 仅选择部分有价值的题 J(2165): 时间旅行 Description 假设 Bobo 位于时间轴(数轴)上 t0 点,他要使用时间机器回到区间 (0, h] 中 ...

  3. HZNU-ACM寒假集训Day3小结 搜索

    简单搜索 1.DFS UVA 548 树 1.可以用数组方式实现二叉树,在申请结点时仍用“动态化静态”的思想,写newnode函数 2.给定二叉树的中序遍历和后序遍历,可以构造出这棵二叉树,方法是根据 ...

  4. 2022寒假集训day2

    day1:学习seach和回溯,初步了解. day2:深度优化搜索 T1 洛谷P157:https://www.luogu.com.cn/problem/P1157 题目描述 排列与组合是常用的数学方 ...

  5. 2014 UESTC暑前集训搜索专题解题报告

    A.解救小Q BFS.每次到达一个状态时看是否是在传送阵的一点上,是则传送到另一点即可. 代码: #include <iostream> #include <cstdio> # ...

  6. 寒假训练——搜索 K - Cycle

    A tournament is a directed graph without self-loops in which every pair of vertexes is connected by ...

  7. 寒假训练——搜索 E - Bloxorz I

    Little Tom loves playing games. One day he downloads a little computer game called 'Bloxorz' which m ...

  8. poj3984《迷宫问题》暑假集训-搜索进阶

    K - 迷宫问题 Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:65536KB     64bit ...

  9. 中南大学2019年ACM寒假集训前期训练题集(基础题)

    先写一部分,持续到更新完. A: 寒衣调 Description 男从戎,女守家.一夜,狼烟四起,男战死沙场.从此一道黄泉,两地离别.最后,女终于在等待中老去逝去.逝去的最后是换尽一生等到的相逢和团圆 ...

随机推荐

  1. input框限制只能输入正整数、字母、小数、汉字

    有时需要限制文本框输入内容的类型,本节分享下正则表达式限制文本框只能输入数字.小数点.英文字母.汉字等代码. 例如,输入大于0的正整数 代码如下: <input onkeyup="if ...

  2. 公众号第三方平台开发 教程二 component_verify_ticket和accessToken的获取

    公众号第三方平台开发 教程一 创建公众号第三方平台 公众号第三方平台开发 教程二 component_verify_ticket和accessToken的获取 公众号第三方平台开发 教程三 微信公众号 ...

  3. Oracle,MySQL,sqlserver三大数据库如何获取系统当前时间

    Oracle中如何获取系统当前时间:用SYSDATE() MySQL中获取系统当前时间主要有以下几点: (1)now()函数以('YYYY-MM-dd HH:mm:SS')返回当前的日期时间,可以直接 ...

  4. MEF 插件式开发之 DotNetCore 初体验

    背景叙述 在传统的基于 .Net Framework 框架下进行的 MEF 开发,大多是使用 MEF 1,对应的命名空间是 System.ComponentModel.Composition.在 Do ...

  5. python全局解释器锁(GIL)

    文章作者:卢钧轶(cenalulu) 本文原文地址:http://cenalulu.github.io/python/gil-in-python/ ,对文章做了适当的修改,加入了一些自己的理解. CP ...

  6. Change事件多参

    @change="(value) => selected(value, item)" selected(val, item) { if (val === true) { th ...

  7. Centos 7.x 安装 Docker-ce

    Centos 下安装 Docker-ce CentOS 7.0, CentOS 7.2: cat > /etc/yum.repos.d/docker-main.repo << -'E ...

  8. Excel破解工作表保护

    宏运行 Public Sub Password_cracking() Const DBLSPACE As String = vbNewLine & vbNewLine Const AUTHOR ...

  9. Linux下查看tomcat控制台输出信息

    1.进入tomcat/logs文件夹下 2.# tail -f catalina.out -f:实时刷新

  10. 【读书笔记】iOS-iOS AirPlay与AppleTV

    享受高清晰影院般的大屏幕电影带来的快乐,单纯的iOS设备实现这些是不可能的.苹果有一套解决方案,iOS设备把这些视频和音效数据无线传输(WiFi或蓝牙)Apple TV,然后由Apple TV将视频和 ...