±¾ÎÄʵÀý½²ÊoÁËphp¼¸¸o¾µaËa¨¡£ÖÏi¸ø´o¼Ò¹(C)´o¼Ò²Î¿¼£¬¾ßÌaÈçÏ£º
ÓÐ5¸oÈË͵ÁËÒ»¶ÑÆ»¹u£¬×¼±¸ÔÚµÚ¶þÌiÖÔß¡£ÍiÉÏ£¬ÓÐÒ»ÈËaÞ³oÀ´£¬°ÑËuÓв˹uÖ³É5Ý£¬µ«ÊǶaÁËÒ»¸o£¬Ë³ÊÖ°ÑÕa¸oÈÓ¸øÊ÷ÉϵĺiÁË£¬×Ô¼ºÏÈÄÃ1/5²ØÁË¡£Ã»Ïeµ½ÆaËuËÄÈËÒ²¶¼ÊÇÕaôÏeµÄ£¬¶¼ÈçµÚÒ»¸oÈËÒ»ÑuÖ³É5ݰѶaµÄÄÇÒ»¸oÈÓ¸øÁ˺i£¬Íµ×ßÁË1/5¡£µÚ¶þÌi£¬´o¼ÒÖÔߣ¬Ò²ÊÇÖ³É5ݶaÒ»¸oÈÓ¸øºiÁË¡£×iºoÒ»ÈËÖÁËһݡ£ÎÊ£º¹²ÓжaÉÙÆ»¹u£¿
for ($i = 1; ; $i++)
{
if ($i%5 == 1) {
//µÚÒ»¸oÈËÈ¡Îa*ÖÖ®Ò»£¬»¹Ê£$t
$t = $i - round($i/5) - 1;
if($t % 5 == 1)
{
//µÚ¶þ¸oÈËÈ¡Îa*ÖÖ®Ò»£¬»¹Ê£$r
$r = $t - round($t/5) - 1;
if($r % 5 == 1)
{
//µÚÈý¸oÈËÈ¡Îa*ÖÖ®Ò»£¬»¹Ê£$s
$s = $r - round($r/5) - 1;
if($s % 5 == 1)
{
//µÚËĸoÈËÈ¡Îa*ÖÖ®Ò»£¬»¹Ê£$x
$x = $s - round($s/5) - 1;
if($x % 5 == 1)
{
//µÚÎa¸oÈËÈ¡Îa*ÖÖ®Ò»£¬»¹Ê£$y
$y = $x - round($x/5) - 1;
if ($y % 5 == 1) {
echo $i;
break;
}
}
}
}
}
}
}
һȺºi×ÓÅųÉһȦ£¬°´1£¬2£¬¡£¬nÒÀ´Î±aºÅ¡£È»ºo´ÓµÚ1Ö»¿ªÊ¼Êý£¬Êýµ½µÚmÖ»,°ÑËuÌß³oȦ£¬´ÓËuºoÃaeÔÙ¿ªÊ¼Êý£¬ÔÙÊýµ½µÚmÖ»£¬ÔÚ°ÑËuÌß³oÈ¥¡£¬Èç´Ë²»Í£µÄ½øÐÐÏÂÈ¥£¬Ö±µ½×iºoֻʣÏÂÒ»Ö»ºi×ÓΪֹ£¬ÄÇÖ»ºi×ӾͽÐ×o´oÍo¡£ÒªÇo±a³ÌÄ£Äa´Ë¹ý³Ì£¬ÊaÈem¡¢n, Êa³o×iºoÄǸo´oÍoµÄ±aºÅ¡£
function king($n, $m){
$monkeys = range(1, $n);
$i=0;
$k=$n;
while (count($monkeys)>1) {
if(($i+1)%$m==0) {
unset($monkeys[$i]);
} else {
array_push($monkeys,$monkeys[$i]);
unset($monkeys[$i]);
}
$i++;
}
return current($monkeys);
}
$a = king(5, 2);
var_dump($a);
ººÅµËþ£¨ÓֳƺÓÄÚËþ£(C)ÎÊÌaÊÇÓ¡¶ÈµÄÒ»¸o¹ÅÀϵĴ«Ëµ¡£¿ªÌi±ÙµØµÄÉñ²ªÀÂeÔÚÒ»¸oÃiÀiÁoÏÂÁËÈý¸u½ð¸ÕʯµÄ°o£¬µÚÒ»¸uÉÏÃaeÌ××Å64¸oÔ²µÄ½ðƬ£¬×i´oµÄÒ»¸oÔÚµ×Ï£¬ÆaÓaÒ»¸o±ÈÒ»¸oС£¬ÒÀ´ÎµþÉÏÈ¥£¬ÃiÀiµÄÖÚÉ®²»¾eµØ°ÑËuÃÇÒ»¸o¸oµØ´ÓÕa¸u°o°aµ½ÁiÒ»¸u°oÉÏ£¬¹ae¶¨¿ÉÀuÓÃÖмaµÄÒ»¸u°o×÷Ϊ°iÖu£¬µ«Ã¿´ÎÖ»ÄÜ°aÒ»¸o£¬¶øÇÒ´oµÄ²»ÄÜ*ÅÔÚСµÄÉÏÃae¡£½a´ð½a¹uÇe×Ô¼ºÔËÐмÆËa£¬³ÌÐo¼uβ²¿¡£Ãae¶ÔÅÓ´oµÄÊý×Ö(Òƶ¯Ô²Æ¬µÄ´ÎÊý)18446744073709551615£¬¿´À´£¬ÖÚÉ®ÃǺľ¡±ÏÉu¾«Á¦Ò²²»¿ÉÄÜÍe³É½ðƬµÄÒƶ¯¡£
ºoÀ´£¬Õa¸o´«Ëµ¾ÍÑݱaΪººÅµËþÓÎÏ*:
1.ÓÐÈý¸u¸Ë×ÓA,B,C¡£A¸ËÉÏÓÐÈo¸Éµu×Ó
2.ÿ´ÎÒƶ¯Ò»¿eµu×Ó,СµÄÖ»ÄܵþÔÚ´oµÄÉÏÃae
3.°ÑËuÓеu×Ó´ÓA¸ËÈ«²¿ÒƵ½C¸ËÉÏ
¾¹ýÑо¿¢ÏÖ£¬ººÅµËþµÄÆƽaºÜ¼oµ¥£¬¾ÍÊÇ°´ÕÕÒƶ¯¹aeÔoÏoÒ»¸o½ÏoÒƶ¯½ðƬ£º
Èç3½×ººÅµËþµÄÒƶ¯£ºA¡uC,A¡uB,C¡uB,A¡uC,B¡uA,B¡uC,A¡uC
´ËÍa£¬ººÅµËþÎÊÌaÒ²ÊdzÌÐoÉe¼ÆÖеľµaµÝ¹eÎÊÌa¡£
function hanoi($n,$x,$y,$z){
if($n==1){
echo 'move disk 1 from '.$x.' to '.$z."\n";
}else{
hanoi($n-1,$x,$z,$y);
echo 'move disk '.$n.' from '.$x.' to '.$z."\n";
hanoi($n-1,$y,$x,$z);
}
}
hanoi(3,'A','B','C');
ʹÓÃPHPÃeÊoðÅÝÅÅÐoºÍ¿iËÙÅÅÐoËa*¨£¬¶ÔÏo¿ÉÒÔÊÇÒ»¸oÊý×e
//¶ÔÊý×eðÅÝÅÅÐo
function bubble_sort($array){
$count = count($array);
if ($count <= 0)
return false;
for($i=0; $i<$count; $i++){
for($j=$count-1; $j>$i; $j¨C){
if ($array[$j] < $array[$j-1]){
$tmp = $array[$j];
$array[$j] = $array[$j-1];
$array[$j-1] = $tmp;
}
}
}
return $array;
}
function quick_sort($array) {
if (count($array) <= 1) return $array;
$key = $array[0];
$left_arr = array();
$right_arr = array();
for ($i=1; $i<count($array); $i++){
if ($array[$i] <= $key)
$left_arr[] = $array[$i];
else
$right_arr[] = $array[$i];
}
$left_arr = quick_sort($left_arr);
$right_arr = quick_sort($right_arr);
return array_merge($left_arr, array($key), $right_arr);
}
ʹÓÃPHPÃeÊo˳Ðo²eÕҺͶþÖ²eÕÒËa¨£¬Ë³Ðo²eÕÒ±ØÐe¿¼ÂÇЧÂÊ£¬¶ÔÏo¿ÉÒÔÊÇÒ»¸oÓÐÐoÊý×e
//ʹÓöþ*Ö²eÕÒÊý×eÖÐij¸oÔªËØ
function bin_sch($array, $low, $high, $k){
if ($low <= $high){
$mid = intval(($low+$high)/2);
if ($array[$mid] == $k){
return $mid;
}elseif ($k < $array[$mid]){
return bin_sch($array, $low, $mid-1, $k);
}else{
return bin_sch($array, $mid+1, $high, $k);
}
}
return -1;
}
дһ¸o¶þάÊý×eÅÅÐoËa*¨º¯Êý£¬¿ÉÒÔµ÷ÓÃphpÄÚÖú¯Êý£¬Äܹ»¾ßÓÐͨÓÃÐÔ
function array_sort($arr, $keys, $order=0) {
if (!is_array($arr)) {
return false;
}
$keysvalue = array();
foreach($arr as $key => $val) {
$keysvalue[$key] = $val[$keys];
}
if($order == 0){
asort($keysvalue);
}else {
arsort($keysvalue);
}
reset($keysvalue);
foreach($keysvalue as $key => $vals) {
$keysort[$key] = $key;
}
$new_array = array();
foreach($keysort as $key => $val) {
$new_array[$key] = $arr[$val];
}
return $new_array;
}
Ï£Íu±¾ÎÄËuÊo¶Ô´o¼ÒPHP³ÌÐoÉe¼ÆÓÐËu°iÖu¡£