22475_SnakesonaPlane

2022-5-16 18:22| 发布者: Hocassian| 查看: 24| 评论: 0|原作者: 肇庆学院ACM合集

摘要:
C:\Users\Administrator\Downloads\2019-10-12-10-14-5-89506473638800-Problem List-采集的数据-后羿采集器.html

Pro.ID

22475

Title

Snakes on a Plane

Title链接

http://10.20.2.8/oj/exercise/problem?problem_id=22475

AC

0

Submit

0

Ratio

-

时间&空间限制

  • Time Limit: 1000/500 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others)
  • 描述

    Assume we have an n × m grid of squares, each filled with either 0 or 1. A snake is a connected sequence of grid squares which has the following properties:

    • Each snake square has a 1 in it

    • Each snake square touches exactly two other snake squares (north/south/east/west), except the first and last square in the sequence (the head and tail of the snake)

    A maximal snake is one in which we cannot add a 1 to either end without either lengthening the snake, combining two snakes together, or violating rule 2 above. The examples below show grids with and without maximal snakes (all empty squares have 0's in them). Notice that the second grid does not have a maximal snake since you can add a 1 at the end of either snake to get a larger snake.

    For this problem, you will be given grids and must count the number of maximal snakes in each.

    输入

    Input will consist of multiple test cases. The first line of each test case will contain two positive integers n  m indicating the number of rows and columns in the grid (the maximum value of each will be 200). The next n lines will consist of m characters ( either '0' or '1' ) specifying the grid.

    The last case is followed by a line containing 0 0 which indicates end-of-input and should not be processed.

    输出

    Description

    Assume we have an n × m grid of squares, each filled with either 0 or 1. A snake is a connected sequence of grid squares which has the following properties:

    • Each snake square has a 1 in it

    • Each snake square touches exactly two other snake squares (north/south/east/west), except the first and last square in the sequence (the head and tail of the snake)

    A maximal snake is one in which we cannot add a 1 to either end without either lengthening the snake, combining two snakes together, or violating rule 2 above. The examples below show grids with and without maximal snakes (all empty squares have 0's in them). Notice that the second grid does not have a maximal snake since you can add a 1 at the end of either snake to get a larger snake.

    For this problem, you will be given grids and must count the number of maximal snakes in each.

    Input

    Input will consist of multiple test cases. The first line of each test case will contain two positive integers n  m indicating the number of rows and columns in the grid (the maximum value of each will be 200). The next n lines will consist of m characters ( either '0' or '1' ) specifying the grid.

    The last case is followed by a line containing 0 0 which indicates end-of-input and should not be processed.

    Output

    For each test case, output a single line containing the number of maximal snakes in the grid.

    Sample Input

    7 10
    1111111110
    0000000010
    1100000011
    1011110001
    1010010001
    1010010111
    1110011100
    7 10
    1111111110
    0000000010
    0001010011
    1011010001
    1010010001
    1010010111
    1110011100
    7 10
    1011111110
    0100000010
    1101011011
    1011010001
    1010010001
    1010010111
    1110011100
    0 0

    Sample Output

    1
    0
    3

    Source

    样例输入

    7 10
    1111111110
    0000000010
    1100000011
    1011110001
    1010010001
    1010010111
    1110011100
    7 10
    1111111110
    0000000010
    0001010011
    1011010001
    1010010001
    1010010111
    1110011100
    7 10
    1011111110
    0100000010
    1101011011
    1011010001
    1010010001
    1010010111
    1110011100
    0 0

    样例输出

    1
    0
    3

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部