約瑟夫環問題設有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;【華南師范大學 五 (分)】
[] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []
From:http://tw.wingwit.com/Article/program/sjjg/201311/22784.html