软件渣渣真的要发愤图强啊,保完研的日子不能荒废,把学得渣一样的数据结构和算法重新捡起来,加油啦~
第一周的编程作业,在这里记录一下,Percolation
public class Percolation {
int[][]id;
int n;
public Percolation(int n)
{
// create n-by-n grid, with all sites blocked
id=new int[n][n];
this.n=n;
for(int a=0;a<n;a++)
{
for(int b=0;b<n;b++)
{
id[a][b]=0;
}
}
}
public void open(int i, int j){
// open site (row i, column j) if it is not open already
id[i-1][j-1]=1;
if(j<n&&i<n&&j>1&&i>1)
{
if((id[i-1][j]==2)||(id[i][j-1]==2)||(id[i-2][j-1]==2)||(id[i-1][j-2]==2))
{
id[i-1][j-1]=2;
}
}
else
{
if(i==1)
{
id[i-1][j-1]=2;
}
else if(j==1&&i<n&&((id[i-1][j]==2)||(id[i][j-1]==