301460: CF275B. Convex Shape

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

Description

Convex Shape

题意翻译

### 题意 有一个 $n \times m$ 的方格阵。开始时,所有的方格都是白色的。小 $Z$ 已经把其中的一些方格(至少 $1$ 个)涂成了黑色。如果在方格中从任意一个黑色方格沿着黑色方格走到另一个黑色方格最多只需要拐弯一次的话,我们就称黑色方格组成的区域为凸多边形。如下图所示,左边是凸多边形而右边的不是。 现在你需要判断一个方阵中黑色格子组成的图形是不是凸多边形。 ### 输入格式 第一行输入两个整数 $n$ , $m$ 表示方格阵的行数和列数( $1 \leqslant n,m \leqslant 50$ ),接下来的 $n$ 行每行是一个长度为 $m$ 由 $W$ 或者 $B$ 组成的字符串,表示方格的颜色为白色或黑色。 ### 输出格式 输出一行,如果图形是凸多边形则输出 $YES$ ,否则输出 $NO$ 。

题目描述

Consider an $ n×m $ grid. Initially all the cells of the grid are colored white. Lenny has painted some of the cells (at least one) black. We call a painted grid convex if one can walk from any black cell to any another black cell using a path of side-adjacent black cells changing his direction at most once during the path. In the figure below, the left grid is convex while the right one is not convex, because there exist two cells which need more than one time to change direction in their path. ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF275B/78281bc2a35cb460c013c77e911494012fd2bb87.png)You're given a painted grid in the input. Tell Lenny if the grid is convex or not.

输入输出格式

输入格式


The first line of the input contains two integers $ n $ and $ m $ $ (1<=n,m<=50) $ — the size of the grid. Each of the next $ n $ lines contains $ m $ characters "B" or "W". Character "B" denotes a black cell of the grid and "W" denotes a white cell of the grid. It's guaranteed that the grid has at least one black cell.

输出格式


On the only line of the output print "YES" if the grid is convex, otherwise print "NO". Do not print quotes.

输入输出样例

输入样例 #1

3 4
WWBW
BWWW
WWWB

输出样例 #1

NO

输入样例 #2

3 1
B
B
W

输出样例 #2

YES

Input

题意翻译

### 题意 有一个 $n \times m$ 的方格阵。开始时,所有的方格都是白色的。小 $Z$ 已经把其中的一些方格(至少 $1$ 个)涂成了黑色。如果在方格中从任意一个黑色方格沿着黑色方格走到另一个黑色方格最多只需要拐弯一次的话,我们就称黑色方格组成的区域为凸多边形。如下图所示,左边是凸多边形而右边的不是。 现在你需要判断一个方阵中黑色格子组成的图形是不是凸多边形。 ### 输入格式 第一行输入两个整数 $n$ , $m$ 表示方格阵的行数和列数( $1 \leqslant n,m \leqslant 50$ ),接下来的 $n$ 行每行是一个长度为 $m$ 由 $W$ 或者 $B$ 组成的字符串,表示方格的颜色为白色或黑色。 ### 输出格式 输出一行,如果图形是凸多边形则输出 $YES$ ,否则输出 $NO$ 。

加入题单

算法标签: