📄 river.pas
字号:
program River_Crossing;
const
num='';
var
f:text;
n,i:word;
t:longint;
a,b:array[1..1005] of byte;
function up(t:integer; time:longint):boolean;
begin
time:=time mod (a[t]+b[t]);
if (1<=time) and (time<=a[t]) then up:=true else up:=false;
end;
function run:longint;
var
last,now:array[0..1010] of boolean;
time:longint;
i,j:integer;
std:boolean;
begin
fillchar(last,sizeof(last),0);
last[0]:=true;
time:=0;
repeat
inc(time);
if last[n+1]=true then begin run:=time-1;exit end;
std:=false;
for i:=0 to n+1 do now[i]:=false;
for i:=0 to n+1 do if (i=0) or (i=n+1) or up(i,time) then
for j:=i-5 to i+5 do if (j>=0) and (j<=n+1) and (last[j]=true) then
begin
std:=true;
now[i]:=true;
break;
end;
last:=now;
until (time>2520) or (not std);
run:=0;
end;
begin
assign(f,'river'+num+'.dat');reset(f);
readln(f,n);
for i:=1 to n do readln(f,a[i],b[i]);
close(f);
assign(f,'river'+num+'.out');rewrite(f);
t:=run;
if t=0 then writeln(f,'NO') else writeln(f,t);
close(f);
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -