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. JQuery EasyUI DataGrid根据条件设置表格行样式(背景色)

    1.javascript定义函数返回样式 <script type="text/javascript"> //根据条件设置表格行背景颜色 function setRow ...

  2. Virtualbox 上调整 Mac OS 分辨率 最简单方法

    Mac OS 分辨率:VBoxManage setextradata "Mac OS X 10.10" VBoxInternal2/EfiGopMode 3       ----代 ...

  3. linux学习第一天,常用命令一

    linux系统基本原则:1.由自由的单一的小程序组成,组合小程序完成负责的任务.2.一切皆文件,3.尽量避免捕获用户接口,也就是说用户输入命令后就能直接返回结果.4.配置文件保存为纯文本格式. GUI ...

  4. 【Python文件处理】递归批处理文件夹子目录内所有txt数据

    因为有个需求,需要处理文件夹内所有txt文件,将txt里面的数据筛选,重新存储. 虽然手工可以做,但想到了python一直主张的是自动化测试,就想试着写一个自动化处理数据的程序. 一.分析数据格式 需 ...

  5. 乐校园单车项目第一天——购买Apple开发者账号、创建SVN

    日常三问: 1. 我应该干什么? 2. 我能干什么? 3. 我想干什么?

  6. nginx配置为windows服务中的坑

    网上搜索“nginx 配置为windows服务”,很容易搜索到使用windows server warpper来配置,于是按照网上的方法我从github上的链接下载了1.17版本,前面都很顺利,很容易 ...

  7. 使用KRPano资源分析工具还原全景图片

    软件交流群:571171251(软件免费版本在群内提供) krpano技术交流群:551278936(软件免费版本在群内提供) 最新博客地址:blog.turenlong.com 限时下载地址:htt ...

  8. Unity3D 接完GVR SDk后如何插入自己的java代码

    1.用Eclipse创建一个Android Application Project 2.用压缩软件打开gvr_android_common.aar和unitygvractivity.aar,分别把里面 ...

  9. windows 中去除Ctrl+Alt+Del才能登录

    安装windows 7后登录的时候有一样很麻烦的步骤是需要先按Ctrl+Alt+Del,才能输入用户密码进行登录.这里笔者介绍一下如何取消这个东西. 点击“开始菜单”,点击“控制面板”. [管理工具] ...

  10. Debian8.3安装flash插件,备用~~~

    debian的浏览器iceweasel默认没有安装flash播放器,flash player这坨shit,容易使浏览器崩溃,但看在线视频又不得不用这货. 有两种安装方法: 一.安装压缩包 1.先去官网 ...