标签:style blog io ar color sp for on div
<?php //约瑟夫环,选猴王 function pickKing($num, $m) { $arr = array(); $a = ‘1‘; for ($i=0; $i<$num; $i++) { $arr[] = $a++; //赋值区 } $i = 1; while (count($arr) > 1) { if ($i % $m != 0) { $arr[] = $arr[$i-1]; //判断区 //print_r($arr); } unset($arr[$i-1]); $i++; } return $arr; } echo ‘<pre>‘; $arr = pickKing(3, 3); print_r($arr); echo ‘</pre>‘; //选猴王2. function yuesefu($n,$m){ $r = 0; for($i=2;$i<=$n;$i++){ $r = ($r+$m)%$i; } return $r+1; } print_r(yuesefu(3,3)); ?>
标签:style blog io ar color sp for on div
原文地址:http://www.cnblogs.com/Xavier13/p/4127595.html