讨论 / 为什么不能fillhar?
苍蝇 2009-07-05 19:06:00
点我顶贴 收藏 删除
该题用二维数组Num 储存结果,如果在begin后加上fillchar(num,sizeof(num),0)的话,只过两个点。

去掉就ac了。why?

var num:array[-1..100,-1..100]of qword;

i,j,m,n,x,y:integer;

function cheak(xm,yn:integer):boolean;

begin

cheak:=true;

if (xm=x)and(yn=y) then cheak:=false;

if (abs(xm-x)=2)and(abs(yn-y)=1)then cheak:=false;

if (abs(xm-x)=1)and(abs(yn-y)=2)then cheak:=false;

end;

begin

readln(m,n,x,y);

num[0,0]:=1;

{fillchar(num,sizeof(num),0);}

for i:=0 to M do

for j:=0 to N do

if cheak(i,j) and((i<>0)or(j<>0)) then

num[i,j]:=num[i-1,j]+num[i,j-1];

writeln(num[M,N]);

readln;

end.

#1 青龙白狐@2009-06-11 19:42:00
回复 删除
你前边num[0,0]:=1,你在fillcharnum[0,0]就等于0了,没初始值了,就wa了......
#2 青龙白狐@2009-06-11 19:42:00
回复 删除
const

dx: array[1 .. 8] of Shortint = (-2, -1, 1, 2, 2, 1, -1, -2);

dy: array[1 .. 8] of Shortint = (1, 2, 2, 1, -1, -2, -2, -1);

var

n, m, x, y, i, j: Byte;

g: array[0 .. 20, 0 .. 20] of Byte;

f: array[0 .. 20, 0 .. 20] of qword;

begin

Readln(n, m, x, y);

Fillchar(g, Sizeof(g), 0);

g[x, y] := 1;

for i := 1 to 8 do

if (x + dx[i] >= 0) and (x + dx[i] <= n) and

(y + dy[i] >= 0) and (y + dy[i] <= m) then

g[x + dx[i], y + dy[i]] := 1;

f[0, 0] := 1;

for i := 1 to n do

if g[i, 0] = 0 then f[i, 0] := f[i - 1, 0];

for i := 1 to m do

if g[0, i] = 0 then f[0, i] := f[0, i - 1];

for i := 1 to n do

for j := 1 to m do

if g[i, j] = 0 then f[i, j] := f[i - 1, j] + f[i, j - 1];

Writeln(f[n, m])

end.

#3 webeskycn@2009-07-05 19:06:00
回复 删除
我顶LS!

说得好!

查看更多回复
提交回复