hdu 1426(DFS+坑爹的输入输出)
Sudoku Killer
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 6798 Accepted Submission(s): 2117
据说,在2008北京奥运会上,会将数独列为一个单独的项目进行比赛,冠军将有可能获得的一份巨大的奖品———HDU免费七日游外加lcy亲笔签名以及同hdu acm team合影留念的机会。
所以全球人民前仆后继,为了奖品日夜训练茶饭不思。当然也包括初学者linle,不过他太笨了又没有多少耐性,只能做做最最基本的数独题,不过他还是想得到那些奖品,你能帮帮他吗?你只要把答案告诉他就可以,不用教他是怎么做的。
数
独游戏的规则是这样的:在一个9x9的方格中,你需要把数字1-9填写到空格当中,并且使方格的每一行和每一列中都包含1-9这九个数字。同时还要保证,
空格中用粗线划分成9个3x3的方格也同时包含1-9这九个数字。比如有这样一个题,大家可以仔细观察一下,在这里面每行、每列,以及每个3x3的方格都
包含1-9这九个数字。
例题:
答案:
对于每组测试数据保证它有且只有一个解。
? 6 5 2 ? 7 1 ? 4
? ? 8 5 1 3 6 7 2
9 2 4 ? 5 6 ? 3 7
5 ? 6 ? ? ? 2 4 1
1 ? 3 7 2 ? 9 ? 5
? ? 1 9 7 5 4 8 6
6 ? 7 8 3 ? 5 1 9
8 5 9 ? 4 ? ? 2 3
3 6 5 2 8 7 1 9 4
4 9 8 5 1 3 6 7 2
9 2 4 1 5 6 8 3 7
5 7 6 3 9 8 2 4 1
1 8 3 7 2 4 9 6 5
2 3 1 9 7 5 4 8 6
6 4 7 8 3 2 5 1 9
8 5 9 6 4 1 7 2 3
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
using namespace std;
int mp[][];
char s[];
int dir[][] ={{-,},{,},{,},{,-}};
struct Node{
int x,y;
}node[];
bool vis[];
int tot;
bool flag;
void getmp(char c,int a,int b){
if(isdigit(c)) mp[a][b] = c-'';
else {
mp[a][b] = ;
node[tot].x = a;
node[tot++].y = b;
}
}
bool judge(int x,int y,int v){
for(int i=;i<=;i++){
if(mp[i][y]==v||mp[x][i]==v) return false;
}
int a = (x-)/,b = (y-)/;
for(int i=a*+;i<=a*+;i++){
for(int j=b*+;j<=b*+;j++){
if(mp[i][j]==v) return false;
}
}
return true;
}
void dfs(int num){
if(!flag) return;
if(num==tot){
flag = false;
for(int i=;i<=;i++){
for(int j=;j<=;j++){
if(j!=)
printf("%d ",mp[i][j]);
else printf("%d\n",mp[i][j]);
}
}
return;
}
for(int i=;i<=;i++){
if(judge(node[num].x,node[num].y,i)){
vis[num] = true;
mp[node[num].x][node[num].y] = i;
dfs(num+);
mp[node[num].x][node[num].y] = ;
vis[num] = false;
}
}
}
int main()
{
int k = ;
while(scanf("%s",s)!=EOF){
tot = ;
flag = true;
getmp(s[],,);
for(int i=;i<=;i++){
scanf("%s",s);
getmp(s[],,i);
}
for(int i=;i<=;i++){
for(int j=;j<=;j++){
scanf("%s",s);
getmp(s[],i,j);
}
}
memset(vis,false,sizeof(vis));
if(k++) printf("\n");
dfs(); }
}
hdu 1426(DFS+坑爹的输入输出)的更多相关文章
- P - Sudoku Killer HDU - 1426(dfs + map统计数据)
P - Sudoku Killer HDU - 1426 自从2006年3月10日至11日的首届数独世界锦标赛以后,数独这项游戏越来越受到人们的喜爱和重视. 据说,在2008北京奥运会上,会将数独列为 ...
- Snacks HDU 5692 dfs序列+线段树
Snacks HDU 5692 dfs序列+线段树 题意 百度科技园内有n个零食机,零食机之间通过n−1条路相互连通.每个零食机都有一个值v,表示为小度熊提供零食的价值. 由于零食被频繁的消耗和补充, ...
- HDU 5143 DFS
分别给出1,2,3,4 a, b, c,d个 问能否组成数个长度不小于3的等差数列. 首先数量存在大于3的可以直接拿掉,那么可以先判是否都是0或大于3的 然后直接DFS就行了,但是还是要注意先判合 ...
- HDU 1426 Sudoku Killer(dfs 解数独)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1426 Sudoku Killer Time Limit: 2000/1000 MS (Java/Oth ...
- hdu 1426:Sudoku Killer(DFS深搜,进阶题目,求数独的解)
Sudoku Killer Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- HDU 1426 Sudoku Killer【DFS 数独】
自从2006年3月10日至11日的首届数独世界锦标赛以后,数独这项游戏越来越受到人们的喜爱和重视. 据说,在2008北京奥运会上,会将数独列为一个单独的项目进行比赛,冠军将有可能获得的一份巨大的奖品— ...
- hdu 1426 Sudoku Killer (dfs)
Sudoku Killer Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- HDU 1426(数独 DFS)
题意是完成数独. 记录全图,将待填位置处填 0,记录下所有的待填位置,初始化结束.在每个待填位置处尝试填入 1 - 9,若经过判断后该位置可以填入某数字,则继续向下填下一个位置, 回溯时把待填位置重新 ...
- hdu 1426 Sudoku Killer
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1426 #include<stdio.h> #include<math.h> #in ...
随机推荐
- MyBatis之二级缓存
二级缓存与一级缓存区别:二级缓存的范围更大,多个sqlSession可以共享一个UserMapper的二级缓存区域. 每一个mapper都有一个自己的二缓存区域(按namespace区分),两个map ...
- 浴谷夏令营例题Codeforces827DBest Edge Weight(三个愿望,一次满足~(大雾
这题在浴谷夏令营wyx在讲的最小生成树的时候提到过,但并没有细讲怎么写... 这题可以用三种写法写,虽然只有两种能过...(倍增/倍增+并查集/树链剖分 先跑出最小生成树,分类讨论,在MST上的边,考 ...
- 关于EK Dicnic
笔记--最大流 $EK$ $Dinic$ $EK$: 运用反向边可以给当前图一次反悔的机会,就是其实现在的增广路并不是最优的,然后就$bfs$找增广路即可 $Dicnic$: 我们发现其实每一次先$ ...
- Cydia Substrate based DexDumper's weakness
得益于Cydia Substrate框架,HOOK Native函数变得简单,也给脱壳带来方便. 像ijiami免费版,360,classes.dex被加密到so文件并运行时释放到内存,因此针对相关函 ...
- could not calculate build plan: Plugin org.apache.maven.plugins:maven-resources-plugin:2.5 or one of(maven报错)
could not calculate build plan: Plugin org.apache.maven.plugins:maven-resources-plugin:2.5 or one of ...
- ufw坑
ufw就是一个iptables的快捷应用.今天被这个给坑了. 一个同时没事随便修改ufw,结果ssh登陆不上,ldap什么的都被阻断了. 直接iptables -F,结果忘了修改policy,直接没法 ...
- distcc配置
原理图: OS: ubuntu Server 12.04 1.安装 apt-get install distcc 2.配置 将文件/etc/default/distcc修改为如下格式 STARTDIS ...
- HDU3046 最大流(最小割)
Pleasant sheep and big big wolf Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
- Makefile $@,$^,$ 作用
/* main.c */ #include "mytool1.h" #include "mytool2.h" int ...
- web api 支持cors
1. configservice //******************* cors start *********************** var urls = Configuration[S ...