该状态没有记录
测试结果1: 测试结果错误.错误结果为:10
正确结果应为:12
测试结果2: 测试结果错误.错误结果为:12
正确结果应为:14
测试结果3: 测试结果错误.错误结果为:14
正确结果应为:16
测试结果4: 测试结果错误.错误结果为:16
正确结果应为:18
测试结果5: 测试结果错误.错误结果为:14
正确结果应为:20
测试结果6: 测试结果错误.错误结果为:16
正确结果应为:20
测试结果7: 测试结果错误.错误结果为:12
正确结果应为:20
测试结果8: 测试结果错误.错误结果为:14
正确结果应为:20
测试结果9: 测试结果错误.错误结果为:12
正确结果应为:20
测试结果10: 测试结果错误.错误结果为:14
正确结果应为:16
我的程序
program rq70;
const step:array[1..4]of -3..3 =(-3,3,-1,1);
type direction=0..1;
rec=record
str:string;
dep:longint;
end;
var s :string;
t,h :array[0..1]of longint;
c :array[0..1,0..1000000]of rec;
procedure reach(st:direction);
var i:longint;
begin
for i:=1 to t[1-st] do
if c[1-st,i].str=c[st,t[st]].str then
begin
writeln(c[1-st,i].dep+c[st,t[st]].dep);
halt;
end;
end;
procedure check(st:direction);
var i:longint;
begin
for i:=1 to t[st]-1 do
if c[st,i].str=c[st,t[st]].str then begin dec(t[st]); exit; end;
reach(st);
end;
function change(s:string; p,q:longint):string;
var ch:char;
begin
ch:=s[p]; s[p]:=s[q]; s[q]:=ch;
exit(s);
end;
procedure expand(st:direction);
var temp:string;
i,p:longint;
begin
inc(h[st]);
temp:=c[st,h[st]].str;
p:=pos(’0’,temp);
for i:=1 to 4 do
if (p+step[i]>0)and(p+step[i]<10) then
begin
inc(t[st]);
c[st,t[st]].dep:=c[st,h[st]].dep+1;
c[st,t[st]].str:=change(temp,p,p+step[i]);
check(st);
end;
end;
procedure dbfs;
begin
h[0]:=0; t[0]:=1;
h[1]:=0; t[1]:=1;
c[0,1].str:=s; c[0,1].dep:=0;
c[1,1].str:=’123804765’; c[1,1].dep:=0;
repeat
if (t[0]<=t[1])and(h[0]<t[0]) then expand(0);
if (t[1]<=t[0])and(h[1]<t[1]) then expand(1);
if h[0]<t[0] then expand(0);
if h[1]<t[1] then expand(1);
until
((h[0]>=t[0])and(h[1]>=t[1]));
end;
begin
readln(s);
dbfs;
end.
program bashumananti;
const
xx:array[1..4]of shortint=(0,-1,0,1);
yy:array[1..4]of shortint=(-1,0,1,0);
type
arr=array[1..3,1..3]of byte;
jl=record
qipan:arr;
fa:longint;
end;
var
str:string[10];
i,j,k,m,n,kkk:longint;
cllose1,cllose2,oppen1,oppen2:longint;
x1,x2:array[1..1000000]of jl;
f1,f2:array[1..1000000]of longint;
procedure init;
begin
m:=0; kkk:=0;
cllose1:=1; oppen1:=1;
cllose2:=1; oppen2:=1;
f1[cllose1]:=0; f2[cllose2]:=0;
x1[1].fa:=0; x2[2].fa:=0;
read(str);
for i:=1 to 3 do
x1[cllose1].qipan[1,i]:=ord(str[i])-ord(’0’);
for i:=4 to 6 do
x1[cllose1].qipan[2,i-3]:=ord(str[i])-ord(’0’);
for i:=7 to 9 do
x1[cllose1].qipan[3,i-6]:=ord(str[i])-ord(’0’);
x2[cllose2].qipan[1,1]:=1; x2[cllose2].qipan[1,2]:=2; x2[cllose2].qipan[1,3]:=3;
x2[cllose2].qipan[2,1]:=8; x2[cllose2].qipan[2,2]:=0; x2[cllose2].qipan[2,3]:=4;
x2[cllose2].qipan[3,1]:=7; x2[cllose2].qipan[3,2]:=6; x2[cllose2].qipan[3,3]:=5;
end;
function same1(chkarr:arr):boolean;
var
i,j,k,kk:integer;
begin
for k:=1 to cllose1-1 do
begin
kk:=0;
for i:=1 to 3 do
for j:=1 to 3 do
if x1[k].qipan[i,j]=chkarr[i,j] then inc(kk) else break;
if kk=9 then exit(true);
end;
exit(false);
end;
function same2(chkarr:arr):boolean;
var
i,j,k,kk:integer;
begin
for k:=1 to cllose2-1 do
begin
kk:=0;
for i:=1 to 3 do
for j:=1 to 3 do
if x2[k].qipan[i,j]=chkarr[i,j] then inc(kk) else break;
if kk=9 then exit(true);
end;
exit(false);
end;
procedure isok1;
var
i,j,k,w:longint;
begin
for k:=1 to oppen2 do
begin
w:=0;
for i:=1 to 3 do
for j:=1 to 3 do
if x1[oppen1].qipan[i,j]=x2[k].qipan[i,j] then inc(w) else break;
if w=9 then
begin
write(f1[oppen1]+f2[k]);
halt;
end;
end;
end;
procedure isok2;
var
i,j,k,w:longint;
begin
for k:=1 to oppen1 do
begin
w:=0;
for i:=1 to 3 do
for j:=1 to 3 do
if x2[oppen2].qipan[i,j]=x1[k].qipan[i,j] then inc(w) else break;
if w=9 then
begin
write(f2[oppen2]+f1[k]);
halt;
end;
end;
end;
procedure search;
var
i,j,k:longint;
i1,j1:shortint;
buffer:arr;
begin
inc(kkk);
if odd(kkk) then
begin
for i:=1 to 3 do
for j:=1 to 3 do
if x1[cllose1].qipan[i,j]=0 then
begin
for k:=1 to 4 do
begin
i1:=i+xx[k];
j1:=j+yy[k];
if (i1>0)and(i1<4)and(j1>0)and(j1<4) then
begin
buffer:=x1[cllose1].qipan;
buffer[i,j]:=buffer[i1,j1];
buffer[i1,j1]:=0;
if not(same1(buffer)) then
begin
inc(oppen1);
x1[oppen1].qipan:=buffer;
f1[oppen1]:=f1[cllose1]+1;
isok1;
end;
end;
end;
end;
inc(cllose1);
end
else
begin
for i:=1 to 3 do
for j:=1 to 3 do
if x2[cllose2].qipan[i,j]=0 then
begin
for k:=1 to 4 do
begin
i1:=i+xx[k];
j1:=j+yy[k];
if (i1>0)and(i1<4)and(j1>0)and(j1<4) then
begin
buffer:=x2[cllose2].qipan;
buffer[i,j]:=buffer[i1,j1];
buffer[i1,j1]:=0;
if not(same2(buffer)) then
begin
inc(oppen2);
x2[oppen2].qipan:=buffer;
f2[oppen2]:=f2[cllose2]+1;
isok2;
end;
end;
end;
end;
inc(cllose2);
end;
end;
begin
init;
repeat
search;
until (cllose1>oppen1) or (cllose2>oppen2);
writeln(’No answer!’);
end.
a:array[1..1000,1..10] of longint;
b,c,d:array[1..1000] of longint;
i,j,k,m,n,t:longint;
begin
readln(n,m,k);
for i:=1 to n do
begin
b[i]:=0; c[i]:=0; d[i]:=i;
for j:=1 to k do
begin
read(a[i,j]); inc(b[i],a[i,j]); inc(c[i],sqr(a[i,j]));
end;
b[i]:=trunc(b[i]/k);
c[i]:=trunc((c[i]-k*sqr(b[i])))/k);
end;
for i:=1 to n-1 do
for j:=i+1 to n do
if (b[i]<b[j]) or ((b[i]=b[j]) and (c[i]>c[j])) or ((b[i]=b[j]) and (c[i]=c[j]) and (d[i]>d[j])) then
begin
t:=b[i]; b[i]:=b[j]; b[j]:=t;
t:=c[i]; c[i]:=c[j]; c[j]:=t;
t:=d[i]; d[i]:=d[j]; d[j]:=t;
end;
for i:=1 to m-1 do write(d[i],' '); write(d[m]);
end.
比如123045678这个数据,
把它看成:
123
045
678
这时如果把0和3交换是不行的
而在123045678格式中,极容易忽视。。。