比赛 20121106 评测结果 AAAAAAAA
题目名称 过河 最终得分 100
用户昵称 亟隐 运行时间 0.033 s
代码语言 Pascal 内存使用 1.15 MiB
提交时间 2012-11-06 11:39:06
显示代码纯文本
var     a,b:array[0..1010]of longint;
        f:array[0..1010,0..1010]of boolean;
        n,i,j,min:longint;

procedure init;
begin
        readln(n); min:=1000;
        for i:=1 to n do read(a[i],b[i]);
        a[n+1]:=1000000; a[0]:=a[n+1];
end;

procedure try(x,y:longint);
var     i,t,l,r:longint;
begin
        if f[x,y] then exit else f[x,y]:=true;
        if x=n+1 then if y<min then min:=y;
        if (x>n)or(y>min) then exit;
        if x-5<0 then l:=0 else l:=x-5;
        if x+5>n+1 then r:=n+1 else r:=x+5;
        for i:=r downto l do
        begin
                if b[i]+a[i]=0 then continue;
                t:=(y+1) mod (b[i]+a[i]);
                if t=0 then t:=a[i]+b[i];
                if t<=a[i] then try(i,y+1);
        end;
end;

procedure work;
begin
        try(0,0);
        for i:=1 to 1001 do if f[n+1,i] then break;
        if f[n+1,i] then writeln(i) else writeln('NO');
end;

begin
assign(input,'rivera.in');reset(input);
assign(output,'rivera.out');rewrite(output);
        init;
        work;
close(input);close(output);
end.