疫情扩散
作者:互联网
101000101来表示3×3的地图,1表示该网格中有疫情,0表示没有,每隔一个时间步,有疫情的网格会向它上下左右四个网格进行扩散,求多少个时间步以后整个地图都有疫情?
import java.util.ArrayList;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
class Point {
int x = -1;
int y = -1;
int sideLength;
Point(int index, int sideLength) {
x = index / sideLength;
y = index - x * sideLength;
this.sideLength = sideLength;
}
int left() {
return x >= 1 ? y * sideLength + x - 1 : y * sideLength + x;
}
int right() {
return x <= sideLength - 2 ? y * sideLength + x + 1 : y * sideLength + x;
}
int top() {
return y >= 1 ? (y - 1) * sideLength + x : y * sideLength + x;
}
int bottom() {
return y <= sideLength - 2 ? (y + 1) * sideLength + x : y * sideLength + x;
}
标签:index,java,疫情,int,sideLength,util,import,扩散 来源: https://blog.csdn.net/dragon_T1985/article/details/114477415