POJ 1363(栈)

此题纯模拟也能过……

   我更懒,直接记栈尾元素和已出元素……

Program P1363;
var
   n,i:longint;
   a:array[1..1000] of longint;
   b:array[0..1000] of boolean;
   t:longint;
   tag:boolean;
begin
   read(n);
   while (n>0) do
   begin
      read(a[1]);
      while (a[1]>0) do
      begin
         fillchar(b,sizeof(b),false);
         for i:=2 to n do read(a[i]);
         t:=a[1];
         b[t]:=true;
         dec(t);
         tag:=false;
         for i:=2 to n do
         begin
            if not(b[a[i]]) then
            begin
               if a[i]>t then
               begin
                  t:=a[i];
                  b[t]:=true;
                  dec(t);
                  while b[t] do dec(t);
               end
               else if a[i]=t then
               begin
                  b[t]:=true;
                  dec(t);
                  while b[t] do dec(t);
               end
               else
               begin
                  writeln('No');
                  tag:=true;
                  break;
               end;
            end
            else
            begin
               writeln('No');
               tag:=true;
               break;
            end;
         end;
         if not(tag) then writeln('Yes');

         read(a[1]);
      end;
      writeln;
      read(n);
   end;
end.

此条目发表在DefaultCategory分类目录,贴了标签。将固定链接加入收藏夹。