Sudoku

Time Limit : 3000/1000ms (Java/Other)   Memory Limit : 65535/65535K (Java/Other)
Total Submission(s) : 19   Accepted Submission(s) : 5
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 [b]Case #x:[/b], 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
 
Source
The 2015 China Collegiate Programming Contest
 
 
/*/
最进学校的课真是让人崩溃啊,作业都快做不过来了,挤个下午刷刷题目,却被一个做过的题目卡了好久,我的天啊。。 题意:
这个题目就是数独,但是是4*4的数独。 补全这个数独。。 一开始少读了一句 2x2 也要保持独立性,WA了一发。。。 AC代码:
/*/
#include "iostream"
#include "cstdio"
#include "cstring"
#include "string"
#include "cmath"
using namespace std;
typedef long long LL;
#define memset(x,y) memset(x,y,sizeof(x))
#define memcpy(x,y) memcpy(x,y,sizeof(x)) const int MX = 1e5 + 100 ;
int _;
int vix[5][5] ,viy[5][5],IXI[3][3][5],maps[5][5];
char tem[5][5];
int flag; void _X_() {
puts("");
puts("");
puts("");
} void Print() {
for(int i=0; i<4; i++) {
for(int j=0; j<4; j++) {
printf("%d",maps[i][j]);
}
puts("");
}
} void init() {
flag=0;
_=0;
memset(vix,0);
memset(viy,0);
memset(IXI,0);
} int DFS(int i,int j,int __) {
if(__==_) {
return flag=1;
}
if(tem[i][j]=='*') {
for(int k=1; k<=4; k++) {
if(vix[j][k]||viy[i][k]||flag||IXI[i/2][j/2][k])continue;
// cout<< __ <<"["<<k<<"]";
maps[i][j]=k;
vix[j][k]=1;
viy[i][k]=1;
IXI[i/2][j/2][k]=1;
if(j<3) DFS(i,j+1,__+1);
else if(i<3) DFS(i+1,0,__+1);
else if(i==3&&j==3) {
DFS(3,3,__+1);
}
if(flag)break;
maps[i][j]=0;
vix[j][k]=0;
viy[i][k]=0;
IXI[i/2][j/2][k]=0;
}
}
if(j<3) DFS(i,j+1,__);
else if(i<3) DFS(i+1,0,__);
return 0;
} int main() {
int T;
while(~scanf("%d",&T)) {
for(int qq=1; qq<=T; qq++) {
init();
for(int i=0; i<4; i++) {
cin>>tem[i];
for(int j=0; j<4; j++) {
if(tem[i][j]=='*') {
maps[i][j]=0;
_++;
} else {
maps[i][j]=tem[i][j]-'0';
vix[j][maps[i][j]]=1;
viy[i][maps[i][j]]=1;
IXI[i/2][j/2][maps[i][j]]=1;
}
}
}
// cout<<_<<endl;
// _X_();
DFS(0,0,0);
printf("Case #%d:\n",qq);
Print();
// _X_();
}
}
return 0;
}

  

 

ACM: ICPC/CCPC Sudoku DFS - 数独的更多相关文章

  1. ACM : POJ 2676 SudoKu DFS - 数独

    SudoKu Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu POJ 2676 Descr ...

  2. 【POJ - 2676】Sudoku(数独 dfs+回溯)

    -->Sudoku 直接中文 Descriptions: Sudoku对数独非常感兴趣,今天他在书上看到了几道数独题: 给定一个由3*3的方块分割而成的9*9的表格(如图),其中一些表格填有1- ...

  3. hduoj 4707 Pet 2013 ACM/ICPC Asia Regional Online —— Warmup

    http://acm.hdu.edu.cn/showproblem.php?pid=4707 Pet Time Limit: 4000/2000 MS (Java/Others)    Memory ...

  4. 2016 ACM/ICPC Asia Regional Shenyang Online 1007/HDU 5898 数位dp

    odd-even number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)T ...

  5. HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011亚洲北京赛区网络赛)

    HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011 亚洲北京赛区网络赛题目) Eliminate Witches! Time Limit: 2000/1000 ...

  6. hdu 5016 点分治(2014 ACM/ICPC Asia Regional Xi'an Online)

    Mart Master II Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)T ...

  7. 训练报告 (2014-2015) 2014, Samara SAU ACM ICPC Quarterfinal Qualification Contest

    Solved A Gym 100488A Yet Another Goat in the Garden   B Gym 100488B Impossible to Guess Solved C Gym ...

  8. 2016 ACM ICPC Asia Region - Tehran

    2016 ACM ICPC Asia Region - Tehran A - Tax 题目描述:算税. solution 模拟. B - Key Maker 题目描述:给出\(n\)个序列,给定一个序 ...

  9. 2014嘉杰信息杯ACM/ICPC湖南程序设计邀请赛暨第六届湘潭市程序设计竞赛

    比赛链接: http://202.197.224.59/OnlineJudge2/index.php/Contest/problems/contest_id/36 题目来源: 2014嘉杰信息杯ACM ...

随机推荐

  1. SAP模板

    用的是kuangbin的模板:http://www.cnblogs.com/kuangbin/archive/2012/09/29/2707955.html ;//点数的最大值 ;//边数的最大值 c ...

  2. linux 下C++查询mysql数据库

    上一节我们看了怎么使用mysql提供的API来连接mysql数据库,现在来看看怎么执行一条简单的查询语句,并且把查询的结果显示出来. 准备工作:首先新建了一个数据库inote,在这个数据库下面新建了一 ...

  3. android3D动画,绕y轴旋转

    原文地址:http://blog.csdn.net/x_i_a_o_h_a_i/article/details/40449847 其实网上的3D旋转的例子很多,在这里我只是想把其代码做一个解释. 先上 ...

  4. Struts开发包结构

  5. iOS Architectures 浅谈

    iOS项目打包,或者只是在项目里面调用第三方静态库抑或是自己新建一个静态库,就要无可避免的和Architectures打交道.Architectures在Targets面板的Build Setting ...

  6. 【Network】修改docker启动默认网桥docker0为自定义网桥

    自定义网桥 除了默认的 docker0 网桥,用户也可以指定网桥来连接各个容器. 在启动 Docker 服务的时候,使用 -b BRIDGE或--bridge=BRIDGE 来指定使用的网桥. 如果服 ...

  7. nginx访问量统计

    1.根据访问IP统计UV awk '{print $1}'  access.log|sort | uniq -c |wc -l 2.统计访问URL统计PV awk '{print $7}' acces ...

  8. IntelliJ IDEA WEB项目的部署配置

    以下内容是我网上找的比较全面了,其中关于facets配置很多地方都没有说明,其实很重要,我加入了自己的理解.其他来自网络.在导入一个项目有问题时,建议先创建一个正确的web项目,然后对比配置项,一般就 ...

  9. 移居 GitHub

    博客很久没能更新了,很多代码也从博客园逐渐转移到 GitHub,欢迎新老用户光顾: https://github.com/kedebug 个人博客:http://kedebug.me/

  10. Python之str()与repr()的区别

    Python之str()与repr()的区别 str()一般是将数值转成字符串,主要面向用户.  repr()是将一个对象转成字符串显示,注意只是显示用,有些对象转成字符串没有直接的意思.如list, ...