简单说来就是固定一个点,枚举找第二个点,可以固定所有点感谢牛客的大佬们的安慰和帮助[牛泪]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;    }}
点赞 3
评论 2
全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务