浙工大姗姗杯round2 CodeForces 116BLittle Pigs and Wolves
来源:互联网 发布:手机上怎么看淘宝分销 编辑:程序博客网 时间:2024/05/17 03:08
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.
2 3PPWW.P
2
3 3P.W.P.W.P
0
In the first example, one possible scenario in which two little pigs get eaten by the wolves is as follows.
#include <iostream>using namespace std;int main(){ int n, m, p = 0; cin >> n >> m; char a[11][11]; for(int i = 0; i < n; i++) cin >> a[i]; for(int i = 0; i < n; i++){ for(int j = 0; j < m; j++){ if(a[i][j] == 'W' && ((a[i-1][j] == 'P') || a[i][j-1] == 'P' || a[i+1][j] == 'P' || a[i][j+1] == 'P')) p++; } } cout << p; return 0;}
- 浙工大姗姗杯round2 CodeForces 116BLittle Pigs and Wolves
- Codeforces 116B Little Pigs and Wolves
- 浙工大姗姗杯round2 CodeForces 103BCthulhu
- 浙工大姗姗杯round2 G
- Codeforces Beta Round #87 (Div. 2) / 116B Little Pigs and Wolves (简单匹配)
- B. Little Pigs and Wolves
- 浙工大姗姗杯round1 A
- 浙工大姗姗杯round1 C
- 浙工大姗姗杯round1 D
- 浙工大姗姗杯round1 E
- 浙工大姗姗杯round1 F
- 浙工大姗姗杯round1 G
- 浙工大姗姗杯round3 A
- CodeForces 460BLittle Dima and Equation 方程项转换,降低方程项遍历范围
- CodeForces 686BLittle Robber Girl's Zoo
- Pigs and chickens
- POJ 2422 The Wolves and the Sheep 笔记
- PIGS
- OpenJudge-49:计算对数
- 解决record is locked by another user
- Kruskal算法(不能运行)
- Android-auto-android-car崛起-黑莓的QNX在汽车领域的未来将如何
- 【贪心】qbxt精英班
- 浙工大姗姗杯round2 CodeForces 116BLittle Pigs and Wolves
- kermit安装及使用
- 网络基础篇(三):交换机工作原理
- Git
- HybridJAVA 与JS交互
- idea快捷键使用
- SSH框架简单集成
- HTTP响应头
- 表单无法提交