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. html5 canvas-变幻函数

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  2. java 文件保存到本地

    private void savePic(InputStream inputStream, String fileName) { OutputStream os = null; try { Strin ...

  3. java正则表达式获得html字符串中<img src>的src中的url地址

    /** * 得到网页中图片的地址 */ public static Set<String> getImgStr(String htmlStr) { Set<String> pi ...

  4. 企业号查询部门id(改版后)

    1.搜索部门,输入"名称" 2.在后面可以查到部门ID

  5. [PHP][位转换积累]之异或运算的简单加密应用

    异或的符号是^.按位异或运算, 对等长二进制模式按位或二进制数的每一位执行逻辑按位异或操作. 操作的结果是如果某位不同则该位为1, 否则该位为0. xor运算的逆运算是它本身,也就是说两次异或同一个数 ...

  6. Mybatis批量操作

    首先,mysql需要数据库连接配置&allowMultiQueries=true jdbc:mysql://127.0.0.1:3306/mybank?useUnicode=true& ...

  7. Android笔记:动画

    android:fromDegrees 起始的角度度数 android:toDegrees 结束的角度度数,负数表示逆时针,正数表示顺时针.如10圈则比android:fromDegrees大3600 ...

  8. JAVA BigDecimal 小数点处理

    1,保留两位小数 方法一:{ double c=3.154215; java.text.DecimalFormat myformat=new java.text.DecimalFormat(" ...

  9. AngularJS2

    //package.json 用来标记本项目所需的npm依赖包{ "name": "angular-quickstart", "version&quo ...

  10. 常用Javascript语法

    1.document.write(""); 输出语句 2.JS中的注释为// 3.传统的HTML文档顺序是:document->html->(head,body) 4. ...