The 2015 China Collegiate Programming Contest H. Sudoku hdu 5547
Sudoku
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)
Total Submission(s): 596 Accepted Submission(s): 216
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!!!
It's guaranteed that there will be exactly one way to recover the board.
****
2341
4123
3214
*243
*312
*421
*134
*41*
**3*
2*41
4*2*
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的更多相关文章
- 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 ...
- The 2015 China Collegiate Programming Contest Game Rooms
Game Rooms Time Limit: 4000/4000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) Submi ...
- 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 ...
- 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 ...
- 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 ...
- The 2015 China Collegiate Programming Contest -ccpc-c题-The Battle of Chibi(hdu5542)(树状数组,离散化)
当时比赛时超时了,那时没学过树状数组,也不知道啥叫离散化(貌似好像现在也不懂).百度百科--离散化,把无限空间中无限的个体映射到有限的空间中去,以此提高算法的时空效率. 这道题是dp题,离散化和树状数 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- XMPP框架下微信项目总结(5)花名册获取(好友列表)
---->概念 ---->添加花名册 ps:添加花名册,启动: 客户端发送请求到服务器获取好友列表信息,同时在项目中创建数据表,并保存好友列表到数据表中. ---->获取服务器保存好 ...
- Jmeter 函数
一._csvRead 函数 _cvsRead函数是从外部读取参数,csvRead函数可以从一个文件中读取多个参数. 步骤: 1.先新建一个文件,例如c.txt,里面的数据存放为 web@qq.com, ...
- AJAX 三级联动
新的封装类 <?php class DBDA { public $host="localhost";//服务器地址 public $uid="root"; ...
- C# 中的Singleton模式
一般写Singleton基本都是一下这个套路 class Singleton { public static Singleton instance; private Singleton() { } p ...
- Task使用小结
Task是.NET推出数据任务处理的工作类,Task的使用也被越来越多的人讲解,这里仅仅介绍Task的部分使用介绍: 1.Task简单创建 --无返回值 Task.Factory.StartNew(( ...
- 【翻译八】java-内存一致性错误
Memory Consistency Errors Memory consistency errors occur when different threads have inconsistent v ...
- Web框架本质
Web框架本质 众所周知,对于所有的Web应用,本质上其实就是一个socket服务端,用户的浏览器其实就是一个socket客户端. #!/usr/bin/env python #coding:utf- ...
- node 初识
跟随startup engineering 已经到了week2了,目前为止课程都没有详细介绍node,恐怕以后也不会讲得太细,只是罗列出了一堆阅读材料供你自学.花了点时间阅读些许,在此做个墨迹. Ho ...
- 6-03使用SQL语句一次型向表中插入多行数据
通过将现有表中的数据添加到已存在的表中: INSERT INTO <表名><列名> SELECT<列名> FROM<源表名> 将UserInfo的数据添 ...
- 第二篇:SOUI源码的获取及编译
源代码的获取 SOUI的源码采用SVN管理. SVN:http://code.taobao.org/svn/soui2 这里主要包含两个目录:trunk 及 third-part. trunk目录保存 ...