- <?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);
- //该片段来自于http://www.codesnippet.cn/detail/241020136631.html
来源: http://www.codesnippet.cn/detail/241020136631.html