约瑟夫环问题设有n个人围坐一圈并按顺时针方向—n编号从第s个人开始进行报数报数到第m个人此人出圈再从他的下一个人重新开始从到m的报数进行下去 直到所有的人都出圈为止
PROCEDURE Josef (A:ARRAY [n] OF integer; sm:integer);
BEGIN
FOR i:= TO n DO A[i]:=i;
sl:=s;
FOR i:=n DOWNTO DO
BEGIN sl:=__()__//计算出圈人s
IF sl= THEN __()__
w:=A[sl];//A[s]出圈
FOR j:=__()__ DO A[j]:=A[j+];
A[i]:=w;
END;
write(出圈序列为)//输出出圈序列
FOR i :=n DOWNTO DO write(A[i]); writeln
END;【华南师范大学 五 (分)】
[] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []