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. ng-repeat里创建的自定义指令

    在ng里,所有的指令在按照意愿正常工作之前的都需要编译一下,包含angularJS的自定义指令. ng模板里的所有指令都会在angularJS加载完毕之后编译一下,所以那些自定义指令和事件才能工作. ...

  2. Python 3.x 连接数据库(pymysql 方式)

    ==================pymysql=================== 由于 MySQLdb 模块还不支持 Python3.x,所以 Python3.x 如果想连接MySQL需要安装 ...

  3. Cosmos —— Big Data at Microsoft

    1, 1,cosmos stores. Cosmos stores data as streams – a file-like structure Streams are split apart in ...

  4. C#操作Excel文件

    .Net平台上对Excel进行操作主要有两种方式.第一种,把Excel文件看成一个数据库,通过OleDb的方式进行读取与操作:第二种,调用Excel的COM组件.两种方式各有特点. 注意一些简单的问题 ...

  5. .NET MVC Filter异常处理

    MVC程序中自带的HandleErrorAttribute,来处理异常,不在显示黄页.前提是在web.config 中 system.web中关闭customerError选项. 但是很多情况下调试异 ...

  6. OC编程之道-接口适配之适配器

    已有的类与新的接口之间不兼容的问题相当普遍,人们已为它找到了一个解决方案.这个解决方案就是适配器. 1 何为适配器 what 适配器的主要作用是把被适配者的行为传递给管道另一端的客户端. 将一个类的接 ...

  7. Cnblogs自定义皮肤css样式-星空观测者

    不知不觉来Cnblogs也这么久了,然而Blogs提供的主题还是依旧那么复古,总觉得阅读起来难免枯燥,虽然我认为做技术不可以太过浮躁,但是一个美观的主题终究是吸引人眼的第一要素. 毕竟这么久了,在博客 ...

  8. myabatis oracle 调用存储过程返回list结果集

    Mapper.xml 配置 <resultMap type="emp" id="empMap"> <id property="emp ...

  9. 常用的java正则表达式

    常用的正则表达式主要有以下几种: 匹配中文字符的正则表达式: [\u4e00-\u9fa5] 评注:匹配中文还真是个头疼的事,有了这个表达式就好办了哦 获取日期正则表达式:\d{4}[年|\-|\.] ...

  10. LeetCode 36 Valid Sudoku

    Problem: Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board ...