We randomly distribute n points on the circumference of a circle. What is the probability that they will all fall in a common semi-circle?
我们先用程序模拟一下这个过程,看看结果会是什么?
算法思想:我们先定义一个点的最大值,然后随机生成N个点,之后对这N个点进行排序,定义两点之间的最大距离为max_distance,把它的初始值设置为最小值点+最大值-最大值点,然后遍历所有点,求的相邻两点之间的最大值,如果max_distance大于半圆周长,说明这些点在同一半圆内。
代码清单: