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 ...
随机推荐
- ASP.NET SignalR 与 LayIM2.0 配合轻松实现Web聊天室(六) 之 Layim源码改造右键菜单--好友、组管理功能的实现。
前言 上一篇中讲解了加好友的流程,本篇将介绍好友管理,群组管理的右键菜单功能.当然由于菜单项目太多,都实现也得花费时间.只讲解一下我是如何从不知道怎么实现右键菜单到会自定义菜单的一个过程.另外呢,针对 ...
- python基础——使用模块
python基础——使用模块 Python本身就内置了很多非常有用的模块,只要安装完毕,这些模块就可以立刻使用. 我们以内建的sys模块为例,编写一个hello的模块: #!/usr/bin/env ...
- UVA 111 History Grading
读题读了好久,其实就是在输入数据时要对数据的位置进行相应的改变 #include<iostream> #include<cstring> #include<cstdio& ...
- ROW_NUMBER()函数的使用
SQL Server数据库ROW_NUMBER()函数的使用是本文我们要介绍的内容,接下来我们就通过几个实例来一一介绍ROW_NUMBER()函数的使用. 实例如下: .使用row_number()函 ...
- gitlab 建仓的流程
repository:仓库 Git global setup: git config --global user.name "Administrator" git config - ...
- .net学习笔记---xml基础知识
一.XML简介 XML是一种标记语言,用于描述数据,它提供一种标准化的方式来来表示文本数据.XML文档以.xml为后缀.需要彻底注意的是XML是区分大小写的. 先从一个简单的XML例子来了解下xml基 ...
- 与你相遇好幸运,Linux常用命令
开机挂载硬盘 cat /etc/fstab /dev/sda1 /mnt/sda1 ext3 defaults 0 0 挂载硬盘 mount /dev/sdb5 /home/dis ...
- 使用Modernizr探测HTML5/CSS3新特性(转载)
转载地址:http://www.cnblogs.com/TomXu/archive/2011/11/18/detecting-html5-css3-features-using-modernizr.h ...
- Delphi强制类型转化和类型约定
强制类型转换时一种技术,通过它能够使编译器把一种类型的变量当做另一种类型. 由于Pascal有定义新类型的功能,因此编译器在调用一个函数时候对形参和实参类型匹配的检查是非常严格的.因此为了能够通过编译 ...
- 序列化悍将Protobuf-Net,入门动手实录
最近在研究web api 2,看了一篇文章,讲解如何提升性能的, 在序列化速度的跑分中,Protobuf一骑绝尘,序列化速度快,性能强,体积小,所以打算了解下这个利器 1:安装篇 谷歌官方没有提供.n ...