编程介的小学生 2020-06-22 07:55 采纳率: 20.5%
浏览 24
已结题

Counting square 怎么计算的呢

Problem Description
There is a matrix of size R rows by C columns. Each element in the matrix is either “0” or “1”. A square is called magic square if it meets the following three conditions.
(1) The elements on the four borders are all “1”.
(2) Inside the square (excluding the elements on the borders), the number of “1”s and the number of “0”s are different at most by 1.
(3) The size of the square is at least 2 by 2.
Now given the matrix, please tell me how many magic square are there in the matrix.

Input
The input begins with a line containing an integer T, the number of test cases.
Each case begins with two integers R, C(1<=R,C<=300), representing the size of the matrix. Then R lines follow. Each contains C integers, either 0 or 1. The integers are separated by a single space.

Output
For each case, output the number of magic square in a single line.

Sample Input
3
4 4
1 1 1 1
1 0 1 1
1 1 0 1
1 1 1 1
5 5
1 0 1 1 1
1 0 1 0 1
1 1 0 1 1
1 0 0 1 1
1 1 1 1 1
2 2
1 1
1 1

Sample Output
3
2
1

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 如何在scanpy上做差异基因和通路富集?
    • ¥20 关于#硬件工程#的问题,请各位专家解答!
    • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
    • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
    • ¥30 截图中的mathematics程序转换成matlab
    • ¥15 动力学代码报错,维度不匹配
    • ¥15 Power query添加列问题
    • ¥50 Kubernetes&Fission&Eleasticsearch
    • ¥15 報錯:Person is not mapped,如何解決?
    • ¥15 c++头文件不能识别CDialog