比赛 20121106 评测结果 WAWAWAWW
题目名称 过河 最终得分 37
用户昵称 warrior 运行时间 0.017 s
代码语言 Pascal 内存使用 0.94 MiB
提交时间 2012-11-06 11:21:51
显示代码纯文本
var q,t:array[0..100000]of longint;n,i,h,e,ans,p:longint;
    a,b:array[0..1000]of longint;

function check(t,i:longint):boolean;
begin if (t mod (a[i]+b[i])>0)and(t mod (a[i]+b[i])<=a[i])then exit(true)
      else exit(false);
end;
function checkyuan(t,i:longint):boolean;
begin if (t mod (a[i]+b[i])>0)and(t mod (a[i]+b[i])<=a[i]+1)then exit(true)
      else exit(false);
end;

begin
 assign(input,'rivera.in');assign(output,'rivera.out');
 reset(input);rewrite(output);
 readln(n); for I:=1 to n  do readln(a[i],b[i]);
 h:=0;e:=1;q[1]:=0;t[0]:=0;
 while h<e do
  begin
   inc(h);//if q[h]<>0 then if checkyuan(t[h]+1,p)=false then continue;

   p:=q[h]-1;
   while (p>0)and(q[h]-p<=5) do
    begin
     if check(t[h]+1,p)=false then break;
     inc(e);q[e]:=p;t[e]:=t[h]+1;
     dec(p);
    end;

   p:=q[h]+1;
   while (p<=n+1)and(p-q[h]<=5) do
    begin
     if p=n+1 then begin ans:=t[h]+1;writeln(ans);close(output);halt;end;
     if check(t[h]+1,p)=false then break;
     inc(e);q[e]:=p;t[e]:=t[h]+1;
     inc(p);
    end;
   if q[h]<>0then if  checkyuan(t[h]+1,q[h]) then
    begin inc(e);q[e]:=q[h];t[e]:=t[h]+1;end;
   if e>80000 then break;
 end;
 writeln('NO'); close(output); 
end.