《Cracking the Coding Interview》——第7章:数学和概率论——题目5

2014-03-20 02:20

题目:给定二维平面上两个正方形,用一条直线将俩方块划分成面积相等的两部分。

解法:穿过对称中心的线会将面积等分,所以连接两个中心即可。如果两个中心恰好重合,那么任意穿过这个点的直线都满足条件。

代码:

1 // 7.5 Given two squares on two-dimensional plane, draw a line to cut them in two parts with equal area.

2 // Answer:

3 //    Apparently the line should go through the center of the two squares.

4 //    If their center coincide, any line that goes through this center will suffice.

5 int main()

6 {

7     return 0;

8 }

 

你可能感兴趣的:(interview)