22845_Balloons

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

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

Pro.ID

22845

Title

Balloons

Title链接

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

AC

1

Submit

6

Ratio

16.67%

时间&空间限制

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

    Both Saya and Kudo like balloons. One day, they heard that in the central park, there will be thousands of people fly balloons to pattern a big image.

    They were very interested about this event, and also curious about the image.

    Since there are too many balloons, it is very hard for them to compute anything they need. Can you help them?

    You can assume that the image is an N*N matrix, while each element can be either balloons or blank.

    Suppose element A andelement B are both balloons. They are connected if:

    i) They are adjacent;

    ii) There is a list of element C1, C2, … , Cn, while A and C1 are connected, C1 and C2 are connected … Cn and B are connected.

    And a connected block means that every pair of elements in the block is connected, while any element in the block is not connected with any element out of the block.

    To Saya, element A (xa, ya) and B (xb, yb) is adjacent if |xa-xb| + |ya-yb| ≤ 1

    But to Kudo, element A (xa, ya) and element B (xb, yb) is adjacent if |xa-xb| ≤ 1 and  |ya-yb| ≤ 1

    They want to know that there's how many connected blocks with there own definition of adjacent?

    输入

    The input consists of several test cases.

    The first line of input in each test case contains one integer N ( 0 < N ≤ 100 ), which represents the size of the matrix.

    Each of the next N lines contains a string whose length is N, represents the elements of the matrix. The string only consists of 0 and 1, while 0 represents a block and 1 represents balloons.

    The last case is followed by a line containing one zero.

    输出

    Description

    Both Saya and Kudo like balloons. One day, they heard that in the central park, there will be thousands of people fly balloons to pattern a big image.

    They were very interested about this event, and also curious about the image.

    Since there are too many balloons, it is very hard for them to compute anything they need. Can you help them?

    You can assume that the image is an N*N matrix, while each element can be either balloons or blank.

    Suppose element A andelement B are both balloons. They are connected if:

    i) They are adjacent;

    ii) There is a list of element C1, C2, … , Cn, while A and C1 are connected, C1 and C2 are connected … Cn and B are connected.

    And a connected block means that every pair of elements in the block is connected, while any element in the block is not connected with any element out of the block.

    To Saya, element A (xa, ya) and B (xb, yb) is adjacent if |xa-xb| + |ya-yb| ≤ 1

    But to Kudo, element A (xa, ya) and element B (xb, yb) is adjacent if |xa-xb| ≤ 1 and  |ya-yb| ≤ 1

    They want to know that there's how many connected blocks with there own definition of adjacent?

    Input

    The input consists of several test cases.

    The first line of input in each test case contains one integer N ( 0 < N ≤ 100 ), which represents the size of the matrix.

    Each of the next N lines contains a string whose length is N, represents the elements of the matrix. The string only consists of 0 and 1, while 0 represents a block and 1 represents balloons.

    The last case is followed by a line containing one zero.

    Output

    For each case, print the case number (1, 2 …) and the connected block's numbers with Saya and Kudo's definition. Your output format should imitate the sample output. Print a blank line after each test case.

    Sample Input

    5
    11001
    00100
    11111
    11010
    10010

    0

    Sample Output

    Case 1: 3 2

    Source

    样例输入

    5
    11001
    00100
    11111
    11010
    10010

    0

    样例输出

    Case 1: 3 2

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部