最新消息: USBMI致力于为网友们分享Windows、安卓、IOS等主流手机系统相关的资讯以及评测、同时提供相关教程、应用、软件下载等服务。

递归变量

IT圈 admin 38浏览 0评论

2024年2月16日发(作者:朱涵菡)

type ty=record x,y:integer;end;

var a,b:array[1..100]of integer;

qx,qy:array[0..410000]of longint;

v:array[-100..100,-100..100]of boolean;

var k,i,j,l:longint;

function go:boolean;

var n,i,j,k,h,t,xx,yy:longint;

begin

for i:= 1 to 201 do for j:= 1 to 201 do

v[i-101,j-101]:=false;

readln(n);

for i:=1to n do

readln(a[i],b[i]);

h:=0;t:=1;

qx[1]:=0;qy[1]:=0;

while h

begin

inc(h); if h>410000 then h:=1;

for i:=1 to n do

begin

xx:=qx[h]+a[i];yy:=qy[h]+b[i];

if

(abs(xx)<=100)and(abs(yy)<=100)and(not(v[xx,yy]) )then

begin

inc(t); if t>410000

then t:=1;

qx[t]:=xx;qy[t]:=yy;

v[xx,yy]:=true;

end;

end;

if v[1,0]and v[-1,0] and v[0,1] and

v[0,-1] then exit(true);

end;

exit(false);

end;

begin

assign(input,'');assign(output,'');

reset(input);rewrite(output);

type ty=record x,y:integer;end;

var a,b:array[1..100]of integer;

qx,qy:array[0..410000]of longint;

v:array[-100..100,-100..100]of boolean;

var k,i,j,l:longint;

function go:boolean;

var n,i,j,k,h,t,xx,yy:longint;

a,b:array[1..100]of integer;

qx,qy:array[0..410000]of longint;

v:array[-100..100,-100..100]of boolean;

begin

for i:= 1 to 201 do for j:= 1 to 201 do

v[i-101,j-101]:=false;

readln(n);

for i:=1to n do

readln(a[i],b[i]);

h:=0;t:=1;

qx[1]:=0;qy[1]:=0;

while h

begin

inc(h); if h>410000 then h:=1;

for i:=1 to n do

begin

xx:=qx[h]+a[i];yy:=qy[h]+b[i];

if

(abs(xx)<=100)and(abs(yy)<=100)and(not(v[xx,yy]) )then

begin

inc(t); if t>410000

then t:=1;

qx[t]:=xx;qy[t]:=yy;

v[xx,yy]:=true;

end;

end;

if v[1,0]and v[-1,0] and v[0,1] and

v[0,-1] then exit(true);

end;

exit(false);

end;

begin

readln(k);

for l:=1 to k do

if go then

writeln('NIE');

close(input);

close(output);

end.

writeln('TAK')

assign(input,'');assign(output,'');

reset(input);rewrite(output);

readln(k);

for l:=1 to k do

else

if go then writeln('TAK') else

writeln('NIE');

close(input);

close(output);

end.

过了

202 崩掉了

注意加红字的部分 放在函数里与函数外 区别很大

关键是放在函数里每次调用都会申请空间而不释放

2024年2月16日发(作者:朱涵菡)

type ty=record x,y:integer;end;

var a,b:array[1..100]of integer;

qx,qy:array[0..410000]of longint;

v:array[-100..100,-100..100]of boolean;

var k,i,j,l:longint;

function go:boolean;

var n,i,j,k,h,t,xx,yy:longint;

begin

for i:= 1 to 201 do for j:= 1 to 201 do

v[i-101,j-101]:=false;

readln(n);

for i:=1to n do

readln(a[i],b[i]);

h:=0;t:=1;

qx[1]:=0;qy[1]:=0;

while h

begin

inc(h); if h>410000 then h:=1;

for i:=1 to n do

begin

xx:=qx[h]+a[i];yy:=qy[h]+b[i];

if

(abs(xx)<=100)and(abs(yy)<=100)and(not(v[xx,yy]) )then

begin

inc(t); if t>410000

then t:=1;

qx[t]:=xx;qy[t]:=yy;

v[xx,yy]:=true;

end;

end;

if v[1,0]and v[-1,0] and v[0,1] and

v[0,-1] then exit(true);

end;

exit(false);

end;

begin

assign(input,'');assign(output,'');

reset(input);rewrite(output);

type ty=record x,y:integer;end;

var a,b:array[1..100]of integer;

qx,qy:array[0..410000]of longint;

v:array[-100..100,-100..100]of boolean;

var k,i,j,l:longint;

function go:boolean;

var n,i,j,k,h,t,xx,yy:longint;

a,b:array[1..100]of integer;

qx,qy:array[0..410000]of longint;

v:array[-100..100,-100..100]of boolean;

begin

for i:= 1 to 201 do for j:= 1 to 201 do

v[i-101,j-101]:=false;

readln(n);

for i:=1to n do

readln(a[i],b[i]);

h:=0;t:=1;

qx[1]:=0;qy[1]:=0;

while h

begin

inc(h); if h>410000 then h:=1;

for i:=1 to n do

begin

xx:=qx[h]+a[i];yy:=qy[h]+b[i];

if

(abs(xx)<=100)and(abs(yy)<=100)and(not(v[xx,yy]) )then

begin

inc(t); if t>410000

then t:=1;

qx[t]:=xx;qy[t]:=yy;

v[xx,yy]:=true;

end;

end;

if v[1,0]and v[-1,0] and v[0,1] and

v[0,-1] then exit(true);

end;

exit(false);

end;

begin

readln(k);

for l:=1 to k do

if go then

writeln('NIE');

close(input);

close(output);

end.

writeln('TAK')

assign(input,'');assign(output,'');

reset(input);rewrite(output);

readln(k);

for l:=1 to k do

else

if go then writeln('TAK') else

writeln('NIE');

close(input);

close(output);

end.

过了

202 崩掉了

注意加红字的部分 放在函数里与函数外 区别很大

关键是放在函数里每次调用都会申请空间而不释放

发布评论

评论列表 (0)

  1. 暂无评论