1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <iostream>
  5. using namespace std;
  6. char s[10][10];
  7.  
  8. int panduan(int row,int cew)
  9. {
  10. for(int i=0;i<4;i++)
  11. {
  12. if(s[row][i]==s[row][cew]&&i!=cew) return 0;
  13. }
  14. for(int j=0;j<4;j++)
  15. {
  16. if(s[j][cew]==s[row][cew]&&j!=row) return 0;
  17. }
  18. int mrow=row;
  19. int mcew=cew;
  20. if(row%2==1) row--;
  21. if(cew%2==1) cew--;
  22. for(int i=row;i<row+2;i++)
  23. {
  24. for(int j=cew;j<cew+2;j++)
  25. {
  26. if(s[i][j]==s[mrow][mcew]&&i!=mrow&&j!=mcew) return 0;
  27. }
  28. }
  29. return 1;
  30. }
  31.  
  32. void dfs(int step)
  33. {
  34. if(step==16)
  35. {
  36. for(int i=0;i<4;i++)
  37. {
  38. for(int j=0;j<4;j++)
  39. {
  40. printf("%c",s[i][j]);
  41. }
  42. printf("\n");
  43. }
  44. }
  45.  
  46. int row=step/4;
  47. int cew=step%4;
  48. if(s[row][cew]=='*')
  49. {
  50. for(int j=1;j<=4;j++)
  51. {
  52. s[row][cew]=j+'0';
  53. if(panduan(row,cew)) dfs(step+1);
  54. s[row][cew]='*';
  55. }
  56. }
  57. else dfs(step+1);
  58. }
  59.  
  60. int main()
  61. {
  62. int cas=0;
  63. int t;
  64. cin>>t;
  65. while(t--)
  66. {
  67. for(int i=0;i<4;i++) scanf("%s",s[i]);
  68. printf("Case #%d:\n",++cas);
  69. dfs(0);
  70. }
  71. return 0;
  72. }

  

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

  1. 3
  2. ****
  3. 2341
  4. 4123
  5. 3214
  6. *243
  7. *312
  8. *421
  9.  
  10. 题目:B - Sudoku
    思路:
    这个题目其实就是一个小一点的数独,因为很小,所以可以用枚举去搜索,完全不用担心会超时。
    方法很简单就是枚举每一个*位置为1234;然后再回溯。
    具体:
    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. Java可以像Python一样方便爬去世间万物

    前言: 之前在大二的时候,接触到了Python语言,主要是接触Python爬虫那一块 比如我们常用的requests,re,beautifulsoup库等等 当时为了清理数据和效率,还专门学了正则表达 ...

  2. MySQL之视图、触发器、事务、存储、函数、流程控制

    一.视图 视图就是一个虚拟表,我们把复杂的sql语句后看到的虚拟表封装起来,给他取个名字,当我们下次使用的时候,就不用再去写复杂的sql语句,直接调用封装后的视图名字,就可以得到我们想要的表,然后就可 ...

  3. Umbraco 7 支持Microsoft Word 2013 发布内容

    本文介绍如何使用Microsoft Word 2013 编写或编辑你的Blogs或新闻页面,甚至不需要打开浏览器, 我将分成两部分来讲. 概述 本例实采用的是Umbraco 7.2 版本,首页效果: ...

  4. VS2010安装MVC3失败的解决方法

    环境:Win 7 x64 原因:在安装MVC3之前,安装过VS2010 SP1,导致MVC3安装,找不到对于的VS2010安装器 vs_setup.msi 问题图片: 解决方法: 一.来自网络的方法 ...

  5. Linux中ansible批量管理软件部署及剧本编写

    服务器版本信息: Centos6.9 [root@db02 ~]# uname -a Linux db02 2.6.32-696.el6.x86_64 #1 SMP Tue Mar 21 19:29: ...

  6. [PHP] 算法-合并两个有序链表为一个有序链表的PHP实现

    合并两个有序的链表为一个有序的链表: 类似归并排序中合并两个数组的部分 1.遍历链表1和链表2,比较链表1和2中的元素大小 2.如果链表1结点大于链表2的结点,该结点放入第三方链表 3.链表1往下走一 ...

  7. [android] 手机卫士手机定位的原理

    手机定位的三种方式:网络定位,基站定位,GPS定位 网络定位,手机连上wifi 2g 3g的时候,手机会有一个ip,误差很大 基站定位,精确度与基站的多少有关,几十米到几公里的误差 GPS定位,至少需 ...

  8. 【Java基础】15、负数的二进制表示方法

    在计算机中,负数以其正值的补码形式表达. 什么叫补码呢?这得从原码,反码说起. 原码:一个整数,按照绝对值大小转换成的二进制数,称为原码. 比如 00000000 00000000 00000000 ...

  9. PHP FastCGI进程管理器PHP-FPM的架构

    一个master进程,支持多个pool,每个pool由master进程监听不同的端口,pool中有多个worker进程.每个worker进程都内置PHP解释器,并且进程常驻后台,支持prefork动态 ...

  10. addEventListener.js

    document.addEventListener("click",function(){ console.log("添加事件监听") }) 举个例子 : 点击 ...