@@ -0,0 +1,1241 @@
+package com.matao.fundamentals.exercises;%0A%0Aimport edu.princeton.cs.algs4.StdDraw;%0Aimport edu.princeton.cs.algs4.StdRandom;%0A%0A/**%0A * Created by matao on 2018/8/22.%0A * %3Cp%3E%0A * An integer N and a double value p (between 0 and 1),%0A * plots N equally spaced dots of size .05 on the circumference of a circle,%0A * and then, with probability p for each pair of points, draws a gray line connecting them.%0A */%0Apublic class Ex_1_1_31 %7B%0A%0A    public static void drawRandConn(int N, double p) %7B%0A        StdDraw.setCanvasSize(1024, 1024);%0A        StdDraw.setScale(-1.0, 1.0);%0A        StdDraw.setPenRadius(.015);%0A%0A        double%5B%5D%5B%5D d = new double%5BN%5D%5B2%5D;%0A        for (int i = 0; i %3C N; i++) %7B%0A            d%5Bi%5D%5B0%5D = Math.cos(2 * Math.PI * i / N);%0A            d%5Bi%5D%5B1%5D = Math.sin(2 * Math.PI * i / N);%0A            StdDraw.point(d%5Bi%5D%5B0%5D, d%5Bi%5D%5B1%5D);%0A        %7D%0A%0A        StdDraw.setPenRadius();%0A%0A        for (int i = 0; i %3C N - 1; i++)%0A            for (int j = i + 1; j %3C N; j++)%0A                if (StdRandom.bernoulli(p))%0A                    StdDraw.line(d%5Bi%5D%5B0%5D, d%5Bi%5D%5B1%5D, d%5Bj%5D%5B0%5D, d%5Bj%5D%5B1%5D);%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        int N = 5;%0A        double p = 0.4;%0A        p = Math.max(0, Math.min(1, p));%0A%0A        drawRandConn(N, p);%0A    %7D%0A%7D%0A

add solution to exercise 1.1.31