8.12 京东笔试第三题
简单说来就是固定一个点,枚举找第二个点,可以固定所有点
感谢牛客的大佬们的安慰和帮助
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int m = in.nextInt();
int n = in.nextInt();
char[][] chess = new char[m][n];
for(int i = 0;i<m;i++){
String s = in.next();
chess[i] = s.toCharArray();
}
int res = 0;
for(int i = 0;i<m;i++){
for(int j = 0;j<n;j++){
if(chess[i][j] == 'X'){
res += cal(chess,i,j);
}
}
}
System.out.println(res);
}
private static int cal(char[][] chess, int i, int j) {
int m = chess.length;
int n = chess[0].length;
int res = 0;
for(int x = 1;i + x < m && j + x < n;x++){
if (chess[i + x][j + x] == 'X' && chess[i + x][j] == 'X' && chess[i][j + x] == 'X')res++;
}
for(int ni = 1;ni+i<m;ni++){
if(j - ni < 0)break;
for(int nj = 1;nj+j<n;nj++){
if(i+ni+nj >= m || j + nj-ni >= n)break;
if (chess[i + ni][j + nj] == 'X' && chess[i + nj][j - ni] == 'X' && chess[i+ni+nj][j + nj-ni] == 'X')res++;
}
}
return res;
}
}
