<?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;//oh ... ... 这是一只坚强的当当。。。
}
echo twoEggProblem(100);
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号