CF116B.Little Pigs and Wolves
普及-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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?
从前,在一个大小为 n×m 的二维网格上生活着若干只小猪和若干只狼。该网格的每个格子要么为空,要么恰好含有一只小猪,要么恰好含有一只狼。
若一只小猪与一只狼所在的格子有一条公共边,则称它们相邻。小猪害怕狼,因此每只小猪至多与一只狼相邻;但每只狼可以与任意数量的小猪相邻。
多年来,它们一直和平共处。但今天,狼群饿了。狼将依次行动:每只狼(按某种顺序)从与其相邻的小猪中选择一只(若存在),并吃掉这只可怜的小猪。该过程不会重复进行,即每只狼最多吃掉一只小猪。一旦某只小猪被吃掉,它便立即消失,无法再被其他狼吃掉。
问:狼最多能吃掉多少只小猪?
输入格式
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.
第一行包含两个整数 n 和 m(1≤n,m≤10),分别表示我们二维网格的行数和列数。接下来是 n 行,每行包含 m 个字符——即该网格的描述。
“.” 表示该格子为空;
“P” 表示该格子中有一只小猪;
“W” 表示该格子中有一只狼。
保证任意一只小猪至多与一只狼相邻。
输出格式
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.

在第一个例子中,两只小猪被狼吃掉的一种可能情形如下所示。

输入解题思路,AI测评打分。不知道怎么写?