2015南阳CCPC H - Sudoku 暴力
H - Sudoku
Time Limit: 1 Sec
Memory Limit: 256 MB
题目连接
无
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
It's guaranteed that there will be exactly one way to recover the board.
Output
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
HINT
题意
让你找到一个4*4的数独的合法解
题解:
直接爆搜就能过
代码:
#include<stdio.h>
#include<iostream>
#include<math.h>
using namespace std; string s[];
int p[][];
int tx[];
int ty[];
int tot = ;
int flag;
int vis[];
int check()
{
for(int i=;i<;i++)
{
vis[]=vis[]=vis[]=vis[]=;
for(int j=;j<;j++)
{
if(p[i][j]==)continue;
if(vis[p[i][j]])return ;
vis[p[i][j]]=;
}
}
for(int j=;j<;j++)
{
vis[]=vis[]=vis[]=vis[]=;
for(int i=;i<;i++)
{
if(p[i][j]==)continue;
if(vis[p[i][j]])return ;
vis[p[i][j]]=;
}
}
vis[]=vis[]=vis[]=vis[]=;
for(int i=;i<;i++)
{
for(int j=;j<;j++)
{
if(p[i][j]==)continue;
if(vis[p[i][j]])return ;
vis[p[i][j]]=;
}
} vis[]=vis[]=vis[]=vis[]=;
for(int i=;i<;i++)
{
for(int j=;j<;j++)
{
if(p[i][j]==)continue;
if(vis[p[i][j]])return ;
vis[p[i][j]]=;
}
}
vis[]=vis[]=vis[]=vis[]=;
for(int i=;i<;i++)
{
for(int j=;j<;j++)
{
if(p[i][j]==)continue;
if(vis[p[i][j]])return ;
vis[p[i][j]]=;
}
}
vis[]=vis[]=vis[]=vis[]=;
for(int i=;i<;i++)
{
for(int j=;j<;j++)
{
if(p[i][j]==)continue;
if(vis[p[i][j]])return ;
vis[p[i][j]]=;
}
}
return ;
}
void dfs(int x)
{
if(flag)return;
if(x==tot){
for(int i=;i<;i++)
{
for(int j=;j<;j++)
printf("%d",p[i][j]);
printf("\n");
}
flag=;
return;}
for(int i=;i<=;i++)
{
p[tx[x]][ty[x]]=i;
if(check())
dfs(x+);
p[tx[x]][ty[x]]=;
}
}
int main()
{
int t;scanf("%d",&t);
for(int cas = ;cas <= t;cas++)
{
tot = ;
flag = ;
for(int i=;i<;i++)
cin>>s[i];
for(int i=;i<;i++)
for(int j=;j<;j++)
if(s[i][j]=='*')
p[i][j]=;
else
p[i][j]=s[i][j]-''; for(int i=;i<;i++)
for(int j=;j<;j++)
if(p[i][j]==)
{
tx[tot]=i;
ty[tot]=j;
tot++;
}
printf("Case #%d:\n",cas);
dfs();
}
}
2015南阳CCPC H - Sudoku 暴力的更多相关文章
- 2015南阳CCPC H - Sudoku 数独
H - Sudoku Description Yi Sima was one of the best counselors of Cao Cao. He likes to play a funny g ...
- 2015南阳CCPC G - Ancient Go 暴力
G - Ancient Go Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 无 Description Yu Zhou likes to play Go wi ...
- 2015南阳CCPC D - Pick The Sticks dp
D - Pick The Sticks Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 无 Description The story happened lon ...
- 2015南阳CCPC A - Secrete Master Plan 水题
D. Duff in Beach Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 无 Description Master Mind KongMing gave ...
- 2015南阳CCPC E - Ba Gua Zhen 高斯消元 xor最大
Ba Gua Zhen Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 无 Description During the Three-Kingdom perio ...
- 2015南阳CCPC F - The Battle of Guandu 多源多汇最短路
The Battle of Guandu Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 无 Description In the year of 200, t ...
- 2015南阳CCPC L - Huatuo's Medicine 水题
L - Huatuo's Medicine Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 无 Description Huatuo was a famous ...
- 2015南阳CCPC G - Ancient Go dfs
G - Ancient Go Description Yu Zhou likes to play Go with Su Lu. From the historical research, we fou ...
- 2015南阳CCPC D - Pick The Sticks 背包DP.
D - Pick The Sticks Description The story happened long long ago. One day, Cao Cao made a special or ...
随机推荐
- hdu 3938 Portal(并查集+离线+kruskal)2011 Multi-University Training Contest 10
搜了题解才把题搞明白.明白之后发现其实题意很清晰,解题思路也很清晰,只是题目表述的很不清晰…… 大意如下—— 给你一个无向图,图中任意两点的距离是两点间所有路径上的某一条边,这条边需要满足两个条件:1 ...
- wireshark tcp 协议分析 z
虽然知道wireshark是抓包神器,只会大概大概用一下,还用一下下tcpdump,略懂一点BPF过滤器,也知道一点怎么用 wirkshark过滤相关的报文,但是对于详细的字段的含义,如何查看TCP的 ...
- 火狐和google游览器的 hack独有识别 css
先来看google的: /* 这针对于webkit内核的游览器.包括苹果谷歌游览器等*/ @media screen and (-webkit-min-device-pixel-ratio:0) { ...
- 翻译【ElasticSearch Server】第一章:开始使用ElasticSearch集群(1)
我们要做的第一件事是安装ElasticSearch.对于多数应用程序,您开始安装和配置,通常忘记这些步骤的重要性,直到发生了糟糕的事情.这章我们将广泛关注ElasticSearch的这部分.请注意本章 ...
- Libsvm的MATLAB调用和交叉验证
今天听了一个师兄的讲课,才发现我一直在科研上特别差劲,主要表现在以下几个方面,(现在提出也为了督促自己在以后的学习工作道路上能够避免这些问题) 1.做事情总是有头无尾,致使知识点不能一次搞透,每次在用 ...
- pcduino+opencv实现人脸追踪摄像头
Pcduino是一款兼容Arduino接口的mini pc,A8架构1Ghz的CPU,计算能力不俗,用来跑OpenCV刚刚好.这里就用他们实现一个可以跟随人脸移动的摄像头. 硬件清单: 1.Pcdui ...
- html 5 canvas 绘制太极demo
一个练习canvas的小案例.其中若有小问题,欢迎大神拍砖……^_* 代码效果预览地址:http://code.w3ctech.com/detail/2500. <div class=" ...
- 从零开始完整Electron桌面开发(1)搭建开发环境
[OTC] # 需要知识 1. 简单的html.javascript.css知识,就是web前端入门知识. 2. 简单命令行的应用,不会也没关系,照着代码敲就行. 3. 下载安装就不说了吧. 4. 本 ...
- HDU 1536 sg-NIM博弈类
题意:每次可以选择n种操作,玩m次,问谁必胜.c堆,每堆数量告诉. 题意:sg—NIM系列博弈模板题 把每堆看成一个点,求该点的sg值,异或每堆sg值. 将多维转化成一维,性质与原始NIM博弈一样. ...
- JSON 省市数据包括港澳
data: [{ name: "北京", cities: ["西城", "东城", "崇文", "宣武&quo ...