题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5547

题目大意:填数独。。。

思路:爆搜

 1 #include <stdio.h>
 2 #include <string.h>
 3 #include <iostream>
 4 #include <algorithm>
 5 using namespace std;
 6 bool row[5][5],col[5][5],siz[5][5];
 7 int G[5][5];
 8 bool flag;
 9 int Num(int x,int y){
10     if(x<=2&&y<=2) return 1;
11     if(x<=2&&y>2) return 2;
12     if(x>2&&y<=2) return 3;
13     if(x>2&&y>2) return 4;
14 }
15 void dfs(int x,int y){
16     if(y>4&&x==4){
17         flag=true;
18         return ;
19     }
20     if(flag) return ;
21     if(y>4) x++,y=1;
22     if(G[x][y]) {
23         dfs(x,y+1);
24         return;
25     }
26     if(flag) return ;
27     for(int i=1;i<=4;i++){
28         if(!row[x][i]&&!col[y][i]&&!siz[Num(x,y)][i]){
29             G[x][y]=i;
30             row[x][i]=col[y][i]=siz[Num(x,y)][i]=true;
31             dfs(x,y+1);
32             if(flag) return ;
33             G[x][y]=0;
34             row[x][i]=col[y][i]=siz[Num(x,y)][i]=false;
35         }
36     }
37 }
38 void init(){
39     flag=false;
40     memset(row,false,sizeof(row));
41     memset(col,false,sizeof(col));
42     memset(siz,false,sizeof(siz));
43 }
44 void solve(int T){
45     printf("Case #%d:\n",T);
46     init();
47     for(int x=1;x<=4;x++){
48         for(int y=1;y<=4;y++){
49             char tmp;
50             scanf(" %c",&tmp);
51             if(tmp=='*'){
52                 G[x][y]=0;
53             }
54             else {
55                 G[x][y]=tmp-'0';
56                 int now=tmp-'0';
57                 row[x][now]=col[y][now]=siz[Num(x,y)][now]=true;
58             }
59         }
60     }
61     dfs(1,1);
62     for(int i=1;i<=4;i++){
63         for(int j=1;j<=4;j++){
64             printf("%d",G[i][j]);
65         }
66         printf("\n");
67     }
68 }
69 int main(){
70     int T;
71     //freopen("C:\\Users\\acm\\Desktop\\ACM\\out.txt","w",stdout);
72     scanf("%d",&T);
73     for(int i=1;i<=T;i++) solve(i);
74 }

转载于:https://www.cnblogs.com/as3asddd/p/6071887.html

HDOJ5547 SudoKu相关推荐

  1. Valid Sudoku leetcode java

    题目: Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board could ...

  2. LeetCode 37. Sudoku Solver--数独求解(回溯法)--Java 3ms,Python 80ms 解法

    题目地址: Write a program to solve a Sudoku puzzle by filling the empty cells. A sudoku solution must sa ...

  3. LeetCode - Valid Sudoku

    题目: Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board could ...

  4. LeetCode Sudoku Solver

    Write a program to solve a Sudoku puzzle by filling the empty cells. Empty cells are indicated by th ...

  5. 36. Valid Sudoku数独判断

    题目:数独填写正确判断 https://leetcode.com/problems/valid-sudoku/description/ Determine if a Sudoku is valid, ...

  6. Valid Sudoku

    Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board could be ...

  7. 【LeetCode从零单排】No36 Valid Sudoku

    题目       判断数独是否成立的一道题,看的是某大神的答案,写的太漂亮了. Determine if a Sudoku is valid, according to: Sudoku Puzzles ...

  8. leetcode之Valid Sudoku有效的数独(一步步改进代码)

    题目链接:Valid Sudoku有效的数独 题目已经十分确定的说了只有1~9,因此标记法无疑是非常好的选择. 基本思路:对行.列.小数独块分别用一个size为9的数组来标记数字1~9在本行(列/块) ...

  9. LA 2659 poj 3076 zoj 3122 Sudoku(精确覆盖 + DLX)

    题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...

最新文章

  1. 计算机组成与设计第五版英文_南京大学计算机考研信息汇总
  2. 【在路上5】实时计算助力派件管控
  3. opencv2 取二进制数据_百亿数据量下,掌握这些Redis技巧你就能Hold全场
  4. python接口测试实战_Python接口测试实战01:七种武器
  5. 钱多多被立案侦查,曾多次因借款合同纠纷被起诉
  6. [linux驱动]proc学习笔记(一)
  7. 虚拟机安装ubuntu14.04.5系统
  8. 计算字符串长度(英文占1个字符,中文汉字占2个字符)
  9. 前端——HTML百度首页制作
  10. 【LEDE】树莓派上玩LEDE终极指南-92-自己编译的LEDE为啥子不能用SSR和KoolProxy?
  11. 兴业银行java面试_【面经】兴业银行信息技术岗面试
  12. xiuno论坛目录结构摸索记录【hook】
  13. vs2015+opencv在xp下使用的问题
  14. 米拓5.3 mysql支持off,Metinfo 5.3.17 前台SQL注入漏洞分析
  15. Linux常用命令大全(史无前例的命令大全)
  16. 花水木之DruParty: Drupal 水滴趴
  17. 解决Android虚拟机启动时System UI isn‘t responding错误
  18. R语言学习记录:proc.time、Sys.time函数
  19. 怎样“管理”你的上司?
  20. html个性签名怎么写,手把手教你写出自己的个性签名

热门文章

  1. 图像匹配与OpenCV模板匹配
  2. usb host控制devie进入suspend模式
  3. 你为什么会沉默,你们为什么又在后退呢?
  4. 这些明星日入斗金,为什么还要贷款?
  5. 在WinAVR中设置Makefile自动编译多个源文件
  6. Windows® CE 系统中的同步机制
  7. linux系统内核参数配置优化,Linux服务器内核参数优化
  8. JQ 全选后获取选中的值_JQ完全学习版本
  9. php8vsgo,vscode编辑好go语言代码要怎么运行
  10. Unity 2017 Game Optimization 读书笔记 The Benefits of Batching