import java.util.ArrayList;
/*
岛屿问题中再加入最长曼哈顿距离
*/
public class 趋势科技2 {
static int max = Integer.MIN_VALUE;
public static void main(String[] args) {
int count = 0;
int[][] nums = new int[][]{
{0,0,0,0,0,1,1,1,1,1},
{0,1,0,0,0,1,0,0,0,1},
{0,0,0,0,0,1,0,0,0,1},
{0,0,0,0,0,1,1,1,1,1},
{0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,1,1,1,0,0,0},
{0,0,0,1,1,1,1,1,0,0},
{1,1,1,1,1,1,1,1,1,0}
};
boolean[][] flag = new boolean[nums.length][nums[0].length];
for(int i=0;i< nums.length;i++){
for(int j=0;j<nums[0].length;j++){
if(nums[i][j]==1&&!flag[i][j]){
dfs(nums,i,j,new ArrayList<>(),flag);
count++;
}
}
}
System.out.println(count);
System.out.println(max);
}
public static void dfs(int[][] nums, int i, int j, ArrayList<int[]> list,boolean[][] flag){
//边界和判断条件
if(i<0||j<0||i>=nums.length||j>=nums[0].length||nums[i][j]==0||flag[i][j])return;
//这里因为要用到网格的1,所以不能设为0,添加了一个flag来做是否走过的判断
flag[i][j] = true;
//使用一个list<int[]> 存一个图形中所有的点,以此来算最大曼哈顿距离
for(int[] pre : list){
int temp = Math.abs(pre[0]-i)+Math.abs(pre[1]-j);
max = Math.max(temp,max);
}
//添加这次的点到list中
list.add(new int[]{i,j});
//遍历四周
dfs(nums,i+1,j,list,flag);
dfs(nums,i,j+1,list,flag);
dfs(nums,i-1,j,list,flag);
dfs(nums,i,j-1,list,flag);
}
}