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大于半圆周长,说明这些点在同一半圆内。
代码清单:
import java.util.Arrays;
import java.util.Random;
public class Npoints {
/**
* @param args
*/
public static void main(String[] args) {
int m = 10000;
int count;
Npoints robot = new Npoints();
for(int n = 1; n <= 8; n++){//一共测试n个点
count = 0;
for(int i = 0; i < m; i++){//每个点做m次测试
if(robot.judge(n) == tr