###Google面试题:扔鸡蛋问题
####原题描述 两个软硬程度一样但未知的鸡蛋,它们有可能都在一楼就摔碎,也可能从一百层楼摔下来没事。有座100层的建筑,要你用这两个鸡蛋通过最少的次数确定哪一层是鸡蛋可以安全落下的最高位置。可以摔碎两个鸡蛋
####方法分析 看到这个题目,最保险的方法就是一层一层试验,但这样只需要一个鸡蛋就可以了。我们现在有两个鸡蛋,完全可以用有更快的方法。
进一步呢?可能试验的方法是二分查找,例如,第一个鸡蛋再50层扔下,如果碎了,第二个鸡蛋从1-49逐层试验;如果没碎,第一个鸡蛋在75层扔下,如果碎了,第二个鸡蛋从51-74逐层试验…但是,这个方法,很容易悲剧,例如,当正好49层是可以安全落下的,需要尝试50次。比只有一个鸡蛋的情况,效果还要差。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # windows installed Wireshark and cygwin | |
| # open cygwin | |
| nc -l 11233 | /c/Program\ Files/Wireshark/Wireshark -k -S -i - | |
| # on reomote Linux box | |
| tcpdump -i eth0 -n -s 0 not port 11233 or 22 -w -|nc <your windows ip> 11233 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| add_source() { | |
| # fix apt-get update 404 not found | |
| # http://askubuntu.com/questions/244822/errors-running-apt-get-update-and-apt-get-install-mysql-server | |
| cat << EOF | |
| deb http://us.archive.ubuntu.com/ubuntu lucid main multiverse universe | |
| deb http://us.archive.ubuntu.com/ubuntu lucid-security main multiverse universe | |
| deb http://us.archive.ubuntu.com/ubuntu lucid-updates main multiverse universe | |
| EOF |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # | |
| # Find all processes that are executing a futex(2) call with op=FUTEX_WAIT | |
| # In some cases this can be helpful in finding deadlock-ed processes. | |
| # | |
| test ! $UID -eq 0 && echo -e "WARNING: Not running as root, only processes for this user are being scanned\n" >&2; | |
| pids=$(ps -u $UID -opid --no-headers) | |
| sub_pid=$(($$+1)) |
NewerOlder

