Sudoku

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)
Total Submission(s): 596    Accepted Submission(s): 216

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 a 4×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!!!

 
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.

 
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
****
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
题意:数独。
分析:暴力
 
 #include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
bool row[][];
bool col[][];
bool squ[][];
int a[][];
int ans[][]; int pos(int x, int y) {
return (x/) * + (y/);
}
bool flag;
void dfs(int x, int y) {
if (flag) return;
if (y > ) y = , x++;
if (x > ) {
for (int i = ; i <= ; i++)
for (int j = ; j <= ; j++) ans[i][j] = a[i][j];
flag = true;
return;
}
if (a[x][y] != ) {
dfs(x, y+);
return;
}
for (int i = ; i <= ; i++) {
if (row[x][i]) continue;
if (col[y][i]) continue;
int z = pos(x, y);
if (squ[z][i]) continue;
row[x][i] = true;
col[y][i] = true;
squ[z][i] = true;
a[x][y] = i;
dfs(x, y+);
a[x][y] = ;
row[x][i] = false;
col[y][i] = false;
squ[z][i] = false;
}
}
char s[];
int main() {
//freopen("h.in", "r",stdin);
int T, cas = ;
scanf("%d", &T);
while (T--) {
printf("Case #%d:\n", ++cas);
for (int i = ; i <= ; i++) {
scanf("%s", s+);
for (int j = ; j <= ; j++) {
if (s[j] == '*') a[i][j] = ;
else a[i][j] = s[j] - '';
}
}
memset(col,,sizeof(col));
memset(row,,sizeof(row));
memset(squ,,sizeof(squ));
memset(ans,,sizeof(ans));
for (int i = ; i <= ; i++) {
for (int j = ; j <= ; j++) {
if (a[i][j] == ) continue;
row[i][a[i][j]] = true;
col[j][a[i][j]] = true;
int z = pos(i, j);
squ[z][a[i][j]] = true;
}
}
flag = false;
dfs(, );
for (int i = ; i <= ; i++) {
for (int j = ; j <= ; j++) printf("%d",ans[i][j]);
printf("\n");
}
}
}

The 2015 China Collegiate Programming Contest H. Sudoku hdu 5547的更多相关文章

  1. The 2015 China Collegiate Programming Contest A. Secrete Master Plan hdu5540

    Secrete Master Plan Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Othe ...

  2. The 2015 China Collegiate Programming Contest Game Rooms

    Game Rooms Time Limit: 4000/4000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Submi ...

  3. The 2015 China Collegiate Programming Contest C. The Battle of Chibi hdu 5542

    The Battle of Chibi Time Limit: 6000/4000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Othe ...

  4. Gym 100952H&&2015 HIAST Collegiate Programming Contest H. Special Palindrome【dp预处理+矩阵快速幂/打表解法】

    H. Special Palindrome time limit per test:1 second memory limit per test:64 megabytes input:standard ...

  5. 2015 HIAST Collegiate Programming Contest H

    A sequence of positive and non-zero integers called palindromic if it can be read the same forward a ...

  6. The 2015 China Collegiate Programming Contest -ccpc-c题-The Battle of Chibi(hdu5542)(树状数组,离散化)

    当时比赛时超时了,那时没学过树状数组,也不知道啥叫离散化(貌似好像现在也不懂).百度百科--离散化,把无限空间中无限的个体映射到有限的空间中去,以此提高算法的时空效率. 这道题是dp题,离散化和树状数 ...

  7. The 2015 China Collegiate Programming Contest L. Huatuo's Medicine hdu 5551

    Huatuo's Medicine Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others ...

  8. The 2015 China Collegiate Programming Contest K Game Rooms hdu 5550

    Game Rooms Time Limit: 4000/4000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total ...

  9. The 2015 China Collegiate Programming Contest G. Ancient Go hdu 5546

    Ancient Go Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total ...

随机推荐

  1. abcd

    [问题描述]有4个长度为N的数组a,b,c,d.现在需要你选择N个数构成数组e,数组e满足a[i]≤e[i]≤b[i]以及 Σe[i]*c[i]=0,并且使得Σe[i]*d[i]最大.[输入格式]输入 ...

  2. 二、获取微信用户openId

    /// <summary> /// 登录首页 /// </summary> /// <returns></returns> public ActionR ...

  3. Android源码-学习随笔

    在线代码网站1:http://grepcode.com/project/repository.grepcode.com/java/ext/com.google.android/android/ 书籍: ...

  4. 重温WCF之数单向通讯、双向通讯、回调操作(五)

    一.单向通讯单向操作不等同于异步操作,单向操作只是在发出调用的瞬间阻塞客户端,但如果发出多个单向调用,WCF会将请求调用放入到服务器端的队列中,并在某个时间进行执行.队列的存储个数有限,一旦发出的调用 ...

  5. 知乎大牛的关于JS解答

    很多疑惑一扫而空.... http://www.zhihu.com/question/35905242?sort=created JS的单线程,浏览器的多进程,与CPU,OS的对位. 互联网移动的起起 ...

  6. 常用的Java代码汇总

    1. 字符串有整型的相互转换           Java   1 2 <strong>Stringa=String.valueOf(2);   //integer to numeric ...

  7. TCP 连接中断的判断

    关于TCP 3次握手,4次分手就不多说了.如何判断TCP连接是否中断是个大问题. 1 TCPKeep-alive 机制 并不是TCP 规范的一部分,实现细节差距大. 2 使用heartbeat 检测 ...

  8. [Eclipse][SVN] 在eclipse上安装SVN

    以前装过好多次SVN,始终没有一次把安装过程记录下来,这次新装机器,安装SVN插件时一波三折,记录下来免得以后又忘记了.   方法一: 1. 直接通过后台添加URL通过互联网进行安装,直接上图: 2. ...

  9. [Linux][Hadoop] 运行WordCount例子

    紧接上篇,完成Hadoop的安装并跑起来之后,是该运行相关例子的时候了,而最简单最直接的例子就是HelloWorld式的WordCount例子.   参照博客进行运行:http://xiejiangl ...

  10. ok6410按键中断编程,linux按键裸机

    6410按键中断编程 一.流程分析 外部中断控制寄存器(s3c6410x  359页) 1.EINTxCONy: 外部中断组x的第y个控制器.这个就是设置中断的触发方式.有5种触发方式. 2.EINT ...