码迷,mamicode.com
首页 > 其他好文 > 详细

Programming Assignment 1: Percolation

时间:2021-02-17 15:10:37      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:assign   word   lock   ring   create   des   系统   size   sam   

Percolation API

public class Percolation {
   public Percolation(int n)                // create n-by-n grid, with all sites blocked
   public void open(int row, int col)       // open site (row, col) if it is not open already
   public boolean isOpen(int row, int col)  // is site (row, col) open?
   public boolean isFull(int row, int col)  // is site (row, col) full?
   public int numberOfOpenSites()           // number of open sites
   public boolean percolates()              // does the system percolate?

   public static void main(String[] args)   // test client (optional)
}

isFull()中,蓝色区域为full,即连通区域内的白色方块。

技术图片

技术图片

 

我们虚设了两个方块,来判断整个系统的连通性,为了解决回渗问题,建立2个检测WeightedUnion.当来到最后一层的时候,一个与n*n+1相连接,一个不连,最后判断isfull()时可以避免回渗问题。

PercolationStats API

 

public class PercolationStats {
  public PercolationStats(int n, int trials)    // perform trials independent experiments on an n-by-n grid
  public double mean()                          // sample mean of percolation threshold
  public double stddev()                        // sample standard deviation of percolation threshold
  public double confidenceLo()                  // low  endpoint of 95% confidence interval
  public double confidenceHi()                  // high endpoint of 95% confidence interval

  public static void main(String[] args)        // test client (described below)
}

 

 


蒙特卡洛算法,对于在n*n个方格图,随机打开一个方格,检测是否percolate。

Programming Assignment 1: Percolation

标签:assign   word   lock   ring   create   des   系统   size   sam   

原文地址:https://www.cnblogs.com/JasonJ/p/14403417.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!