比赛 20101117 评测结果 EEEEEEEEEE
题目名称 教官 最终得分 0
用户昵称 itachi 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2010-11-17 11:12:53
显示代码纯文本
program tt(input,output);

var
back,data,seat:array[1..10000] of integer;
n,i,j,head,step,temp:integer;   num:extended;
 procedure change(a,b:integer);
  begin
    if (b=head)  and (a=n)
      then
      begin
       back[seat[a]]:=b;
       back[seat[a-1]]:=-1;
       head:=seat[a];
       exit;
      end;
  back[seat[a-1]]:=b;
   back[seat[a]]:=back[b];

  back[b]:=seat[a];
  end;
  function check:boolean;
  var
  i,j:integer;
  begin
    i:=head; j:=1;
    check:=true;
    repeat
     if i <> j then check:=false;
     seat[j]:=i;
     i:=back[i];
     inc(j);
    until i=-1;

  end;
begin
assign(input,'officer.in');
reset(input);
assign(output,'officer.out');
rewrite(output);
readln(n);
for i:= 1 to n do
readln(data[i]);
close(input);
for i:= 1 to  n do
 begin
 seat[i]:=i;

 back[i]:=i+1;
 end;
 back[n]:=-1;
  head:=1; num:=0;
 repeat
  num:=num+1;
  step:= trunc(num) mod n;
  if step=0 then step:=n;
  if seat[step]= head  then head:= back[head];
  change(step,seat[data[step]]);

 until check;

  writeln(num:0:0);
  close(output);
end.