algorithms
昆仑山白泽
这个作者很懒,什么都没留下…
展开
-
A Google's Interview Question - GLAT #20 series 1
Question:Consider a function which, for a given whole number n, returns the number of ones required when writing out all numbers between 0 and n. For example, f(13) = 6. Notice that f(1) = 1. What's...2007-02-08 02:22:00 · 114 阅读 · 0 评论 -
Another Google question - drop glassballs from a building 5
Here are some results are the testcases:1. PathFindTest.test4Ball100Floors():The result is like this:path=(f=56, b=3, whole, tried)-->(f=91, b=3, broken, tried)-->(f=71, b=2, broken, tried)...2007-05-13 04:01:02 · 99 阅读 · 0 评论 -
Another Google question - drop glassballs from a building 4
The test cases are divided into 3 classes.The first one is just a pinpoint test class that contains some corner cases:java 代码 package glassball; import junit.framework.TestCas...2007-05-13 03:42:03 · 108 阅读 · 0 评论 -
Another Google question - drop glassballs from a building 3
The next step is to find the actually path of floors that we are going through to find the breaking floor. Here is the code to do that.java 代码 package glassball; import java.uti...2007-05-13 03:33:43 · 208 阅读 · 0 评论 -
Another Google question - drop glassballs from a building 2
Here is the code following the logic from the previous post:java 代码 package glassball; import java.util.List; import java.util.ArrayList; /** * Google i...2007-05-13 03:02:02 · 115 阅读 · 0 评论 -
Another Google question - drop glassballs from a building 1
Here is the question:原题: 有一个100层高的大厦,你手中有两个相同的玻璃围棋子。从这个大厦的某一层扔下围棋子就会碎,用你手中的这两个玻璃围棋子,找出一个最优的策略,来得知那个临界层面。I copied and pasted the above since I can't type Chinese most of the time. A google yield a ...2007-05-12 04:43:00 · 116 阅读 · 0 评论 -
Given n coins and a pan balance,find the only counterfeit 4
The Utils class is composed of some common methods:java 代码 package solve; import scale.Ball; import scale.Scale; import java.util.Iterator; import java....2007-02-27 05:54:00 · 113 阅读 · 0 评论 -
Given n coins and a pan balance,find the only counterfeit 3
In the 1-ball case, if the status flag is already set, then we don't need to weight anymore. Otherwise, we need to find a good ball to compare.java 代码 package solve; import scale...2007-02-27 05:50:00 · 114 阅读 · 0 评论 -
Given n coins and a pan balance,find the only counterfeit 2
Now it comes to the Scale class. The main job of it is to weight both sides. So the class is pretty simple, sum the weights of balls and compare.Now based on these classes, the translation of the al...2007-02-27 05:29:00 · 118 阅读 · 0 评论 -
Given n coins and a pan balance, find the only counterfeit 1
The problem is: There is one counterfeit coin among 12 coins. It is unknown whether the counterfeit is lighter or heavier than a genuine coin(all genuine coins weigh the same). Using 3 weighings on ...2007-02-27 04:49:00 · 148 阅读 · 0 评论 -
A Google's Interview Question - GLAT #20 series 4
The entire class is as follows:java 代码 /** * GOOGLE GLAT question #20: * Consider a function which, for a given whole number n, returns the number * of ones required when writi...2007-02-08 02:36:00 · 135 阅读 · 0 评论 -
A Google's Interview Question - GLAT #20 series 3
The roadmap to compute all fixed points of f(x) is to start from boundaries 1, or 10^10, and keep acting f on it. If x is a boundary point, first compare x and f(x) to see whether we should generate t...2007-02-08 02:36:00 · 127 阅读 · 0 评论 -
A Google's Interview Question - GLAT #20 series 2
Now, we can deduct the recursion formula on digits Lemma 4Let n = a_k * 10^k + a_(k-1) * 10^(k-1) + ....... + a_1 * 10 + a_0denote the base 10 expansion, thenwhen a_k = 1 (A) f(n) = f(n...2007-02-08 02:24:00 · 114 阅读 · 0 评论 -
Revisit 一道应聘智力题的编程求解, Einstein puzzle
Another brain teaser, titled 一道应聘智力题的编程求解, http://www.iteye.com/topic/608112. This is the Einsten's puzzle. There are a few variations but the puzzle is the same. The consensus is that the...2010-03-09 00:36:07 · 243 阅读 · 0 评论