HDU5547-Sudoku
来源:互联网 发布:数据库能干什么 编辑:程序博客网 时间:2024/06/11 02:22
Sudoku
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 2217 Accepted Submission(s): 752
Problem Description
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 a4×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×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!!!
Actually, Yi Sima was playing it different. First of all, he tried to generate a
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, T(1≤T≤100) . T 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.
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 x is the test case number (starting from 1). Then output 4 lines with 4 characters each. indicate the recovered board.
Sample Input
3****234141233214*243*312*421*134*41***3*2*414*2*
Sample Output
Case #1:1432234141233214Case #2:1243431234212134Case #3:3412123423414123
Source
The 2015 China Collegiate Programming Contest
Recommend
wange2014
解题思路:记录下所有‘*’的位置,然后爆搜
#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <algorithm>#include <cmath>#include <map>#include <set>#include <stack>#include <queue>#include <vector>#include <bitset>using namespace std;#define LL long longconst LL INF = 0x3f3f3f3f3f3f3f3f;const double pi = acos(-1.0);const double eps = 1e-8;char ch[10][10];struct node{int x, y, ans;} a[20];int cnt, flag;bool check(int x, int y,int k){for (int i = 0; i<4; i++){if (ch[x][i] == '0'+k||ch[i][y] == '0'+k) return false;}int xx = x / 2 * 2, yy = y / 2 * 2;for (int i = xx; i <= xx + 1; i++)for (int j = yy; j <= yy + 1; j++)if (ch[i][j] == '0'+k) return false;return true;}void dfs(int k){if (k == cnt){flag = 1;return;}for (int i = 1; i <= 4; i++){if (check(a[k].x, a[k].y, i)){ch[a[k].x][a[k].y] = i + '0';dfs(k + 1);if (flag) return;ch[a[k].x][a[k].y] = '*';}}}int main(){int t, cas = 0;scanf("%d", &t);while (t--){printf("Case #%d:\n", ++cas);cnt = 0;for (int i = 0; i<4; i++){scanf("%s", ch[i]);for (int j = 0; j<4; j++){if (ch[i][j] == '*')a[cnt].x = i, a[cnt++].y = j;}}flag = 0;dfs(0);for (int i = 0; i<4; i++) puts(ch[i]);}return 0;}
0 0
- HDU5547-Sudoku
- hdu5547 Sudoku (暴力DFS)
- 2015 南阳 CCPC hdu5547 Sudoku(DFS)
- HDU5547 Sudoku(深搜DFS)(2015CCPC)
- HDU5547
- 【HDU5547 2015 CCPC 南阳国赛H】【DFS】Sudoku 4x4棋盘的填充
- hdu5547 dfs
- hdu5547(深搜)
- 2015南阳CCPC Hdu5547
- Sudoku
- sudoku
- Sudoku
- sudoku
- Sudoku
- Sudoku
- sudoku
- sudoku
- Sudoku
- C++ 类的构造函数constructor
- 利用C语言绘制正弦函数
- Java编程思想-09接口
- ObjectAnimator之PropertyValuesHolder与Keyframe----实现电话响铃震动和小球自由抛体效果
- getopt()函数
- HDU5547-Sudoku
- 机器学习logistic的原理与python 实现
- 三张图读懂机器学习:基本概念、五大流派与九种常见算法
- 二叉树创建,遍历和求最大值
- 集群与负载均衡系列——nginx实现tomcat集群与负载均衡(1)
- 用usb to ttl线给stm32f103zet6开发板下载程序
- Spiral Matrix II
- 白盒测试技术
- 二叉树的先序、中序以及后序遍历(递归与非递归方法)