ACM: ICPC/CCPC Sudoku DFS - 数独
Sudoku
Time Limit : 3000/1000ms (Java/Other) Memory Limit : 65535/65535K (Java/Other)
Total Submission(s) : 19 Accepted Submission(s) : 5
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!!!
/*/
最进学校的课真是让人崩溃啊,作业都快做不过来了,挤个下午刷刷题目,却被一个做过的题目卡了好久,我的天啊。。 题意:
这个题目就是数独,但是是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 - 数独的更多相关文章
- ACM : POJ 2676 SudoKu DFS - 数独
SudoKu Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu POJ 2676 Descr ...
- 【POJ - 2676】Sudoku(数独 dfs+回溯)
-->Sudoku 直接中文 Descriptions: Sudoku对数独非常感兴趣,今天他在书上看到了几道数独题: 给定一个由3*3的方块分割而成的9*9的表格(如图),其中一些表格填有1- ...
- 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 ...
- 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 ...
- HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011亚洲北京赛区网络赛)
HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011 亚洲北京赛区网络赛题目) Eliminate Witches! Time Limit: 2000/1000 ...
- 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 ...
- 训练报告 (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 ...
- 2016 ACM ICPC Asia Region - Tehran
2016 ACM ICPC Asia Region - Tehran A - Tax 题目描述:算税. solution 模拟. B - Key Maker 题目描述:给出\(n\)个序列,给定一个序 ...
- 2014嘉杰信息杯ACM/ICPC湖南程序设计邀请赛暨第六届湘潭市程序设计竞赛
比赛链接: http://202.197.224.59/OnlineJudge2/index.php/Contest/problems/contest_id/36 题目来源: 2014嘉杰信息杯ACM ...
随机推荐
- js中bind,call,apply方法的应用
最近用js的类写东西,发现一个无比蛋疼的事,那就是封装的类方法中的this指针经常会改变指向,失去上下文,导致程序错误或崩溃. 比如: function Obj(){ this.type = &quo ...
- Android的Intent.FLAG_ACTIVITY_CLEAR_TOP无效
转载:http://blog.csdn.net/u011361576/article/details/48626237 今天写代码遇到了一个问题: 当 B - A - B 跳转的时候,使用Intent ...
- 整理一下Entity Framework的查询 [转]
Entity Framework是个好东西,虽然没有Hibernate功能强大,但使用更简便.今天整理一下常见SQL如何用EF来表达,Func形式和Linq形式都会列出来(本人更喜欢Func形式). ...
- [MySQL] 分页优化
在传统的分页思路影响下,很多人都形成了对于分页的固定理解,也就是给出select语句,先用count()函数计算出总的条目,除与每个页面大小pagesize,然后用ceil取整,得出总的页数,用lim ...
- 最终版的Web(Python实现)
天啦,要考试了,要期末考试了,今天把最终版的Python搭建Web代码先写这里记下了.详细的过程先不写了. 这次是在前面的基础上重写 HTTPServer 与 BaseHTTPRequestHandl ...
- mac 给某个目录添加权限
1 cd 到这个目录的上一层目录 2 sudo chmod -R 777 3 输入密码 4 完成
- React学习笔记-5-初始化阶段介绍
初始化阶段可以使用的函数:getDefaultProps:只调用一次,实例之间共享引用.只有在组件的第一个实例被初始化的时候,才会调用他,然后react会把这个函数的返回结果保存起来,从第二个实例开始 ...
- runtime运行时
/** * Describes the instance variables declared by a class. * * @param cls The class to inspect. * @ ...
- LINUX 6.x 内核升级全过程
1. 准备工作 确认内核及版本信息 [root@hostname ~]# uname -r 2.6.32-220.el6.x86_64 [root@hostname ~]# cat /etc/cent ...
- SQL Server数据阻塞原因
阻塞形成原因 是由于SQL Server是高并发的,同一时间会有很多用户访问,为了保证数据一致性和数据安全,引入了锁的机制.同一时间只有拿到钥匙的用户能够访问,而其他用户需要等待. 死锁形成四大必要条 ...