POJ 1068(找规律)

内容目录

(+1;(-1,用sum表示当前的值,

当sum>=1时,w[i]=i-j+1;( j 表示最后加的一段的右边结点的序数)

Program P1068;
Var
   t,i,j,n:longint;
   p:array[0..20] of longint;
function w:longint;
var
   j,sum:longint;
begin
   if p[i]-p[i-1]>0  then exit(1);
   j:=i;
   sum:=0;
   while (true) do
   begin
      inc(sum,p[j]-p[j-1]);
      if sum>=1 then exit(i-j+1)
      else dec(sum);
      dec(j);
   end;
end;
begin
   read(t);
   p[0]:=0;
   while t>0 do
   begin
      read(n);
      for i:=1 to n-1 do
      begin
         read(p[i]);
         write(w,' ');
      end;
      read(p[n]);
      i:=n;
      writeln(w);
      dec(t);
   end;
end.