...1594x第五:xx98x65xx第六:x25
编辑: admin 2017-26-03
-
4
至少有两个以上解.
解1:
581362497
397481625
264597138
876215943
439876512
125934786
942753861
713648259
658129374
解2:
581362497
397481625
264597138
876215943
439876512
125934876
942653781
613748259
758129364
类似问题
类似问题1: 000004020009000000050200000060000000001002007000008150014090000000000030000800904[英语科目]
7 8 6 5 1 4 3 2 9
2 4 9 3 7 6 5 8 1
1 5 3 2 8 9 4 7 6
4 6 5 1 3 7 8 9 2
8 3 1 9 5 2 6 4 7
9 2 7 6 4 8 1 5 3
5 1 4 7 9 3 2 6 8
6 9 8 4 2 1 7 3 5
3 7 2 8 6 5 9 1 4
附解题程序代码
program zk;{20:16 -22:12}
const n=9;
var
i,j,a,b,c,t,p:longint;
map:array [1..9,1..9] of longint;
hang,lie,gong:array [1..9,1..9] of boolean;
h,l,g:array [1..9] of longint;
ok:boolean;
wei:array [1..9,1..9] of longint=((1,1,1,2,2,2,3,3,3),(1,1,1,2,2,2,3,3,3),(1,1,1,2,2,2,3,3,3),(4,4,4,5,5,5,6,6,6),(4,4,4,5,5,5,6,6,6),(4,4,4,5,5,5,6,6,6),(7,7,7,8,8,8,9,9,9),(7,7,7,8,8,8,9,9,9),(7,7,7,8,8,8,9,9,9));
lin,lll:array [1..10] of longint;
procedure print;
var
a,b:longint;
begin
for a:=1 to 9 do
begin
for b:=1 to 9 do
write(map[a,b],' ');
writeln;
end;
end;
procedure sou(k,z:longint);
var
s:longint;
begin
if z=10 then begin inc(k); z:=1; end;
if (k=10) and (z=1) then begin print; ok:=true; exit; end;
if k=10 then exit;
if map[lin[k],lll[z]]=0
then
for s:=1 to 9 do
if (hang[lin[k],s]=false) and (gong[wei[lin[k],lll[z]],s]=false) and (lie[lll[z],s]=false) then
begin
map[lin[k],lll[z]]:=s;
hang[lin[k],s]:=true; lie[lll[z],s]:=true; gong[wei[lin[k],lll[z]],s]:=true;
sou(k,z+1);
if ok then exit;
hang[lin[k],s]:=false; lie[lll[z],s]:=false; gong[wei[lin[k],lll[z]],s]:=false;
map[lin[k],lll[z]]:=0;
end else
else sou(k,z+1);
end;
begin
assign(input,'sudoku.in');
assign(output,'sudoku.out');
reset(input);
rewrite(output);
readln(t);
for p:=1 to t do
begin
for i:=1 to 9 do
begin
lin[i]:=i;
lll[i]:=i;
end;
fillchar(hang,sizeof(hang),false);
fillchar(lie,sizeof(lie),false);
fillchar(gong,sizeof(gong),false);
fillchar(h,sizeof(h),0);
fillchar(l,sizeof(l),0);
fillchar(g,sizeof(g),0);
ok:=false;
for i:=1 to 9 do
begin
for j:=1 to 9 do
begin
read(map[i,j]);
if map[i,j]0 then
begin
hang[i,map[i,j]]:=true; inc(h[i]);
lie[j,map[i,j]]:=true; inc(l[j]);
gong[wei[i,j],map[i,j]]:=true; inc(g[wei[i,j]]);
end;
end;
readln;
end;
for i:=1 to n do
for j:=i to n do
if h[i]
类似问题2: 100000709030000020020050306470100000058000200000408000003060000000049650000001002[数学科目]
*-----------------------------------------------*
| 1 6 5| 2 3 4| 7 8 9|
| 7 3 9| 8 1 6| 5 2 4|
| 8 2 4| 9 5 7| 3 1 6|
|---------------+---------------+---------------|
| 4 7 2| 1 9 5| 8 6 3|
| 9 5 8| 6 7 3| 2 4 1|
| 3 1 6| 4 2 8| 9 7 5|
|---------------+---------------+---------------|
| 5 4 3| 7 6 2| 1 9 8|
| 2 8 1| 3 4 9| 6 5 7|
| 6 9 7| 5 8 1| 4 3 2|
*-----------------------------------------------*
类似问题3: 【数独】百度作业帮
类似问题4: 070000169000010800000807300030002008002000500600700030003603000005080000986000020[数学科目]
类似问题5: 【九宫格数独答案670200010000004000000300009305040000004900058000006900240650000908000006036020007】百度作业帮[数学科目]
用候选数法解
|679|285|314|
|823|194|675|
|451|367|289|
|395|748|162|
|164|932|758|
|782|516|943|
|247|659|831|
|918|473|526|
|536|821|497|