编程介的小学生 2017-03-15 07:56 采纳率: 20.5%
浏览 938
已采纳

Prison Break

In a prison, there are R*C rooms, and there are N prisoners in it, each in a room.

For example: (R=5, C=6, N=7, 'P' means prisoner, '.' means empty)

        ......
        ..P...
        .PPP..
        ..P..P
        .....P

On the first day, all the prisoners do not know each other, so a prisoner can only enter the rooms connected to his own which are empty. Two rooms are connected only when they share a wall.

    R\C 123456
    1   ......
    2   ..P...
    3   .PPP..
    4   ..P..P
    5   .....P

in this case, the (R3,C3) one can't go anywhere, but the others can go to any place marked with '.', they can even get out of the prison.

On the second day, all the prisoners can't find a way to get out of the prison (out of the R*C area) are so disappointed so they kill themselves and turn to be ghosts.

('G' means ghost)

        ......
        ..P...
        .PGP..
        ..P..P
        .....P

On the third day, all the prisoners alive know about the story about ghosts and are so scared that they decide to escape from the prison, so they make their rooms not only connected to the rooms sharing a wall with theirs, but also to the rooms diagonal adjacent. Of course, all the prisoners won't go into a room with a ghost.

On the Fourth day, the officer in the prison feels something uncommon, so he puts a guard in each empty room. Now, the prisoners can only enter the rooms adjacent to theirs which with a prisoner in it.

('X' means a guard)

        XXXXXX
        XXPXXX
        XPGPXX
        XXPXXP
        XXXXXP

On the Fifth day, all the prisoners make a group with all the prisoners whose rooms they can arrive and get ready for the escape.

('1' means group 1, '2' means group 2)

        XXXXXX
        XX1XXX
        X1G1XX
        XX1XX2
        XXXXX2

On the Sixth day, the guards are so tired and they go home to sleep. Each group of prisoners get out of the prison finally.

        ......
        ......
        ......
        ......
        ......

Above is the story of prison break, however, of all the groups, what is the greatest number of prisoners in a group?

Input

The input contains multiple test cases(no more than 20 test cases). Each test case contains three parts:

1 Two integers R(1<= R <= 1000), C(1<= C <=1000) as mentioned above.

2 R rows each with C characters, the description of the prison on the first day. '.' means empty, 'P' means prisoner.

3 an empty line.

Process to the end-of-file.

Output

For each test case print a single line that contains answer.

Sample Input

5 6
......
..P...
.PPP..
..P..P
.....P

5 6
PPPP.P
....P.
......
......
PPPP.P

Sample Output

4
6

  • 写回答

1条回答

  • threenewbee 2017-03-15 07:53
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP