300606: CF116B. Little Pigs and Wolves

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Little Pigs and Wolves

题意翻译

## 题目描述 在一个大小为$n*m$的二维网格里有几只猪和几只狼,这个网格里每一个单元只包含一只猪或一只狼。 如果猪和狼在同一条公共边上,则我们就说他们相邻。因为小猪怕狼,所以每只猪旁边只可能会有一只狼,但是每只狼旁边可能会有好几头猪。 狼将选择其中与其相邻的一头并吃掉,此过程将不再重复。也就是说,一头狼只能吃一头猪,而小猪在被吃掉后会消失且不能被别的狼吃。 求最多有多少只猪会被狼吃掉。 ## 输入格式 第一行包含两个整数n和m$(1<=n,m<=10)$,分别表示网格的行数和列数。 接下来n行,每行m个字符输入网格。其中“.”表示此格为空,“P”代表小猪,“W”代表狼。 数据保证任意一个小猪至多与一个狼相邻。 ## 输出格式 最多有几个小猪会被狼吃掉。

题目描述

Once upon a time there were several little pigs and several wolves on a two-dimensional grid of size $ n×m $ . Each cell in this grid was either empty, containing one little pig, or containing one wolf. A little pig and a wolf are adjacent if the cells that they are located at share a side. The little pigs are afraid of wolves, so there will be at most one wolf adjacent to each little pig. But each wolf may be adjacent to any number of little pigs. They have been living peacefully for several years. But today the wolves got hungry. One by one, each wolf will choose one of the little pigs adjacent to it (if any), and eats the poor little pig. This process is not repeated. That is, each wolf will get to eat at most one little pig. Once a little pig gets eaten, it disappears and cannot be eaten by any other wolf. What is the maximum number of little pigs that may be eaten by the wolves?

输入输出格式

输入格式


The first line contains integers $ n $ and $ m $ ( $ 1<=n,m<=10 $ ) which denotes the number of rows and columns in our two-dimensional grid, respectively. Then follow $ n $ lines containing $ m $ characters each — that is the grid description. "." means that this cell is empty. "P" means that this cell contains a little pig. "W" means that this cell contains a wolf. It is guaranteed that there will be at most one wolf adjacent to any little pig.

输出格式


Print a single number — the maximal number of little pigs that may be eaten by the wolves.

输入输出样例

输入样例 #1

2 3
PPW
W.P

输出样例 #1

2

输入样例 #2

3 3
P.W
.P.
W.P

输出样例 #2

0

说明

In the first example, one possible scenario in which two little pigs get eaten by the wolves is as follows. ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF116B/fb25895f5a70e2b1fef0cf4619270f69e2caabf8.png)

Input

题意翻译

## 题目描述 在一个大小为$n*m$的二维网格里有几只猪和几只狼,这个网格里每一个单元只包含一只猪或一只狼。 如果猪和狼在同一条公共边上,则我们就说他们相邻。因为小猪怕狼,所以每只猪旁边只可能会有一只狼,但是每只狼旁边可能会有好几头猪。 狼将选择其中与其相邻的一头并吃掉,此过程将不再重复。也就是说,一头狼只能吃一头猪,而小猪在被吃掉后会消失且不能被别的狼吃。 求最多有多少只猪会被狼吃掉。 ## 输入格式 第一行包含两个整数n和m$(1<=n,m<=10)$,分别表示网格的行数和列数。 接下来n行,每行m个字符输入网格。其中“.”表示此格为空,“P”代表小猪,“W”代表狼。 数据保证任意一个小猪至多与一个狼相邻。 ## 输出格式 最多有几个小猪会被狼吃掉。

加入题单

算法标签: