[php]代码库
<? php
function twoEggProblem($hight) {
return ceil((sqrt(8 * $hight + 1) - 1) / 2);
}
echo twoEggProblem(100);
//好吧,我改改:test是一台蛋碎机,0表示不碎,1表示碎
function twoEggProblem($hight) {
$len = ceil((sqrt(8 * $hight + 1) - 1) / 2);
$lenForFor = $len + 1;
$rs = 0;
for ($i = 1; $i <= $len; $i++) {
$_len = $lenForFor - $i;
$rs += $_len;
if (test($rs) == 0) continue;
$rs -= $_len;
for ($j = 1; $j < $_len; $j++) {
$rs += 1;
if (test($rs) == 1) return $rs;
}
return ++$rs;
}
return 0;//不碎
}
echo twoEggProblem(100);
//该片段来自于http://yuncode.net